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

@@ -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,