Resolve image/video issues during upload by using local URI.
This commit is contained in:
6
app.json
6
app.json
@@ -2,18 +2,18 @@
|
||||
"expo": {
|
||||
"name": "imexmobile",
|
||||
"slug": "imexmobile",
|
||||
"version": "1.0.12",
|
||||
"version": "1.1.0",
|
||||
"orientation": "default",
|
||||
"icon": "./assets/logo192noa.png",
|
||||
"ios": {
|
||||
"supportsTablet": true,
|
||||
"bundleIdentifier": "com.imex.imexmobile",
|
||||
"buildNumber": "1.0.12.1",
|
||||
"buildNumber": "1.1.0.1",
|
||||
"googleServicesFile": "./GoogleService-Info.plist"
|
||||
},
|
||||
"android": {
|
||||
"package": "com.imex.imexmobile",
|
||||
"versionCode": 1001201,
|
||||
"versionCode": 1010001,
|
||||
"googleServicesFile": "./google-services.json"
|
||||
},
|
||||
"splash": {
|
||||
|
||||
@@ -57,6 +57,10 @@ export function ImageBrowserScreen({
|
||||
}
|
||||
|
||||
const onDone = async (data) => {
|
||||
console.log(
|
||||
"🚀 ~ file: screen-media-browser.component.jsx ~ line 60 ~ data",
|
||||
data
|
||||
);
|
||||
logImEXEvent("imexmobile_upload_documents", { count: data.length });
|
||||
|
||||
//Validate to make sure the totals for the file sizes do not exceed the total on the job.
|
||||
@@ -73,6 +77,7 @@ export function ImageBrowserScreen({
|
||||
const totalOfUploads = await data.reduce(async (acc, val) => {
|
||||
//Get the size of the file based on URI.
|
||||
const info = await FileSystem.getInfoAsync(val.uri, { size: true });
|
||||
|
||||
return (await acc) + info.size;
|
||||
}, 0);
|
||||
|
||||
@@ -112,7 +117,7 @@ export function ImageBrowserScreen({
|
||||
const result = await handleUpload(
|
||||
{
|
||||
//iOS provides the file name. Android does not.
|
||||
uri: p.uri,
|
||||
|
||||
filename,
|
||||
mediaId: p.id,
|
||||
onError: handleOnError,
|
||||
|
||||
@@ -5,8 +5,12 @@ import { Button, View, Text } from "react-native";
|
||||
import { Title } from "react-native-paper";
|
||||
import { purgeStoredState } from "redux-persist";
|
||||
import SignOutButton from "../sign-out-button/sign-out-button.component";
|
||||
import * as Updates from "expo-updates";
|
||||
|
||||
export default function ScreenSettingsComponent() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
console.log(Constants.manifest);
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
@@ -22,9 +26,9 @@ export default function ScreenSettingsComponent() {
|
||||
number: Constants.manifest.version,
|
||||
})}
|
||||
</Title>
|
||||
<Text>{Updates.releaseChannel}</Text>
|
||||
<SignOutButton />
|
||||
<Button title="Purge State" onPress={() => purgeStoredState()} />
|
||||
<Text>Test Channel</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
17
env.js
17
env.js
@@ -44,10 +44,19 @@ const ENV = {
|
||||
};
|
||||
|
||||
function getEnvVars() {
|
||||
let env = Updates.releaseChannel;
|
||||
if (env === null || env === undefined || env === "") return ENV.test;
|
||||
if (env.indexOf("test") !== -1) return ENV.test;
|
||||
if (env.indexOf("default") !== -1) return ENV.prod;
|
||||
if (process.env.NODE_ENV === "development") return ENV.test;
|
||||
|
||||
let releaseChannel = Updates.releaseChannel;
|
||||
if (
|
||||
releaseChannel === null ||
|
||||
releaseChannel === undefined ||
|
||||
releaseChannel === ""
|
||||
)
|
||||
return ENV.test;
|
||||
if (releaseChannel.indexOf("development") !== -1) return ENV.test;
|
||||
|
||||
if (releaseChannel.indexOf("test") !== -1) return ENV.test;
|
||||
if (releaseChannel.indexOf("default") !== -1) return ENV.prod;
|
||||
else return ENV.prod;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ const INITIAL_STATE = {
|
||||
cameraJob: null,
|
||||
documentUploadInProgress: null,
|
||||
documentUploadError: null,
|
||||
deleteAfterUpload: true,
|
||||
deleteAfterUpload: false,
|
||||
};
|
||||
|
||||
const appReducer = (state = INITIAL_STATE, action) => {
|
||||
|
||||
@@ -12,19 +12,24 @@ var cleanAxios = axios.create();
|
||||
cleanAxios.interceptors.request.eject(axiosAuthInterceptorId);
|
||||
|
||||
export const handleUpload = async (ev, context) => {
|
||||
const { uri, filename, mediaId, onError, onSuccess, onProgress } = ev;
|
||||
const { filename, mediaId, onError, onSuccess, onProgress } = ev;
|
||||
const { bodyshop, jobId } = context;
|
||||
|
||||
const newFile = await (await fetch(uri)).blob();
|
||||
let extension = ev.uri.split(".").pop();
|
||||
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
||||
|
||||
const newFile = await (await fetch(imageData.localUri)).blob();
|
||||
|
||||
let extension = imageData.localUri.split(".").pop();
|
||||
|
||||
let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace(
|
||||
/\.[^/.]+$/,
|
||||
""
|
||||
)}`;
|
||||
|
||||
const res = await uploadToCloudinary(
|
||||
key,
|
||||
mediaId,
|
||||
imageData,
|
||||
extension,
|
||||
newFile.type,
|
||||
newFile,
|
||||
@@ -39,6 +44,7 @@ export const handleUpload = async (ev, context) => {
|
||||
export const uploadToCloudinary = async (
|
||||
key,
|
||||
mediaId,
|
||||
imageData,
|
||||
extension,
|
||||
fileType,
|
||||
file,
|
||||
@@ -91,10 +97,11 @@ export const uploadToCloudinary = async (
|
||||
if (onProgress) onProgress({ percent: e.loaded / e.total });
|
||||
},
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("file", {
|
||||
uri: photo.uri,
|
||||
uri: imageData.localUri,
|
||||
type: fileType,
|
||||
name: file.data.name,
|
||||
});
|
||||
@@ -135,8 +142,6 @@ export const uploadToCloudinary = async (
|
||||
return { success: false, error: cloudinaryUploadResponse.statusText };
|
||||
}
|
||||
|
||||
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
||||
|
||||
//Insert the document with the matching key.
|
||||
const documentInsert = await client.mutate({
|
||||
mutation: INSERT_NEW_DOCUMENT,
|
||||
|
||||
Reference in New Issue
Block a user