Resolve image/video issues during upload by using local URI.
This commit is contained in:
@@ -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