Resolve image/video issues during upload by using local URI.

This commit is contained in:
Patrick Fic
2021-05-21 08:27:41 -07:00
parent f4b045bc33
commit 5dc046cc39
6 changed files with 39 additions and 16 deletions

View File

@@ -2,18 +2,18 @@
"expo": { "expo": {
"name": "imexmobile", "name": "imexmobile",
"slug": "imexmobile", "slug": "imexmobile",
"version": "1.0.12", "version": "1.1.0",
"orientation": "default", "orientation": "default",
"icon": "./assets/logo192noa.png", "icon": "./assets/logo192noa.png",
"ios": { "ios": {
"supportsTablet": true, "supportsTablet": true,
"bundleIdentifier": "com.imex.imexmobile", "bundleIdentifier": "com.imex.imexmobile",
"buildNumber": "1.0.12.1", "buildNumber": "1.1.0.1",
"googleServicesFile": "./GoogleService-Info.plist" "googleServicesFile": "./GoogleService-Info.plist"
}, },
"android": { "android": {
"package": "com.imex.imexmobile", "package": "com.imex.imexmobile",
"versionCode": 1001201, "versionCode": 1010001,
"googleServicesFile": "./google-services.json" "googleServicesFile": "./google-services.json"
}, },
"splash": { "splash": {

View File

@@ -57,6 +57,10 @@ export function ImageBrowserScreen({
} }
const onDone = async (data) => { const onDone = async (data) => {
console.log(
"🚀 ~ file: screen-media-browser.component.jsx ~ line 60 ~ data",
data
);
logImEXEvent("imexmobile_upload_documents", { count: data.length }); 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. //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) => { const totalOfUploads = await data.reduce(async (acc, val) => {
//Get the size of the file based on URI. //Get the size of the file based on URI.
const info = await FileSystem.getInfoAsync(val.uri, { size: true }); const info = await FileSystem.getInfoAsync(val.uri, { size: true });
return (await acc) + info.size; return (await acc) + info.size;
}, 0); }, 0);
@@ -112,7 +117,7 @@ export function ImageBrowserScreen({
const result = await handleUpload( const result = await handleUpload(
{ {
//iOS provides the file name. Android does not. //iOS provides the file name. Android does not.
uri: p.uri,
filename, filename,
mediaId: p.id, mediaId: p.id,
onError: handleOnError, onError: handleOnError,

View File

@@ -5,8 +5,12 @@ import { Button, View, Text } from "react-native";
import { Title } from "react-native-paper"; import { Title } from "react-native-paper";
import { purgeStoredState } from "redux-persist"; import { purgeStoredState } from "redux-persist";
import SignOutButton from "../sign-out-button/sign-out-button.component"; import SignOutButton from "../sign-out-button/sign-out-button.component";
import * as Updates from "expo-updates";
export default function ScreenSettingsComponent() { export default function ScreenSettingsComponent() {
const { t } = useTranslation(); const { t } = useTranslation();
console.log(Constants.manifest);
return ( return (
<View <View
style={{ style={{
@@ -22,9 +26,9 @@ export default function ScreenSettingsComponent() {
number: Constants.manifest.version, number: Constants.manifest.version,
})} })}
</Title> </Title>
<Text>{Updates.releaseChannel}</Text>
<SignOutButton /> <SignOutButton />
<Button title="Purge State" onPress={() => purgeStoredState()} /> <Button title="Purge State" onPress={() => purgeStoredState()} />
<Text>Test Channel</Text>
</View> </View>
); );
} }

17
env.js
View File

@@ -44,10 +44,19 @@ const ENV = {
}; };
function getEnvVars() { function getEnvVars() {
let env = Updates.releaseChannel; if (process.env.NODE_ENV === "development") return ENV.test;
if (env === null || env === undefined || env === "") return ENV.test;
if (env.indexOf("test") !== -1) return ENV.test; let releaseChannel = Updates.releaseChannel;
if (env.indexOf("default") !== -1) return ENV.prod; 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; else return ENV.prod;
} }

View File

@@ -5,7 +5,7 @@ const INITIAL_STATE = {
cameraJob: null, cameraJob: null,
documentUploadInProgress: null, documentUploadInProgress: null,
documentUploadError: null, documentUploadError: null,
deleteAfterUpload: true, deleteAfterUpload: false,
}; };
const appReducer = (state = INITIAL_STATE, action) => { const appReducer = (state = INITIAL_STATE, action) => {

View File

@@ -12,19 +12,24 @@ var cleanAxios = axios.create();
cleanAxios.interceptors.request.eject(axiosAuthInterceptorId); cleanAxios.interceptors.request.eject(axiosAuthInterceptorId);
export const handleUpload = async (ev, context) => { 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 { bodyshop, jobId } = context;
const newFile = await (await fetch(uri)).blob(); const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
let extension = ev.uri.split(".").pop();
const newFile = await (await fetch(imageData.localUri)).blob();
let extension = imageData.localUri.split(".").pop();
let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace( let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace(
/\.[^/.]+$/, /\.[^/.]+$/,
"" ""
)}`; )}`;
const res = await uploadToCloudinary( const res = await uploadToCloudinary(
key, key,
mediaId, mediaId,
imageData,
extension, extension,
newFile.type, newFile.type,
newFile, newFile,
@@ -39,6 +44,7 @@ export const handleUpload = async (ev, context) => {
export const uploadToCloudinary = async ( export const uploadToCloudinary = async (
key, key,
mediaId, mediaId,
imageData,
extension, extension,
fileType, fileType,
file, file,
@@ -91,10 +97,11 @@ export const uploadToCloudinary = async (
if (onProgress) onProgress({ percent: e.loaded / e.total }); if (onProgress) onProgress({ percent: e.loaded / e.total });
}, },
}; };
const formData = new FormData(); const formData = new FormData();
formData.append("file", { formData.append("file", {
uri: photo.uri, uri: imageData.localUri,
type: fileType, type: fileType,
name: file.data.name, name: file.data.name,
}); });
@@ -135,8 +142,6 @@ export const uploadToCloudinary = async (
return { success: false, error: cloudinaryUploadResponse.statusText }; return { success: false, error: cloudinaryUploadResponse.statusText };
} }
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
//Insert the document with the matching key. //Insert the document with the matching key.
const documentInsert = await client.mutate({ const documentInsert = await client.mutate({
mutation: INSERT_NEW_DOCUMENT, mutation: INSERT_NEW_DOCUMENT,