Corrected imgproxy uploading.
This commit is contained in:
@@ -145,7 +145,7 @@ export const uploadToImgproxy = async (
|
|||||||
},
|
},
|
||||||
transformRequest: [(data) => data], //Dave had this magical solution because Axios makes no sense.
|
transformRequest: [(data) => data], //Dave had this magical solution because Axios makes no sense.
|
||||||
onUploadProgress: (e) => {
|
onUploadProgress: (e) => {
|
||||||
if (onProgress) onProgress({ percent: (e.loaded / e.total) * 100 });
|
if (onProgress) onProgress({ percent: e.loaded / e.total, loaded: e.loaded });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -157,58 +157,32 @@ export const uploadToImgproxy = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// const s3UploadResponse = await cleanAxios.put(
|
const s3UploadResponse = await cleanAxios.put(
|
||||||
// preSignedUploadUrlToS3,
|
|
||||||
// file,
|
|
||||||
// options
|
|
||||||
// );
|
|
||||||
|
|
||||||
const task = FileSystem.createUploadTask(
|
|
||||||
preSignedUploadUrlToS3,
|
preSignedUploadUrlToS3,
|
||||||
imageData.localUri,
|
file,
|
||||||
{
|
options
|
||||||
httpMethod: "PUT",
|
|
||||||
//uploadType: FileSystem.FileSystemUploadType.MULTIPART,
|
|
||||||
//mimeType: fileType,
|
|
||||||
//headers: {},
|
|
||||||
// parameters: {...OTHER PARAMS IN REQUEST},
|
|
||||||
},
|
|
||||||
(progressData) => {
|
|
||||||
const sent = progressData.totalBytesSent;
|
|
||||||
const total = progressData.totalBytesExpectedToSend;
|
|
||||||
const progress = sent / total;
|
|
||||||
if (onProgress)
|
|
||||||
onProgress({
|
|
||||||
percent: Number(progress.toFixed(2)) * 100,
|
|
||||||
loaded: sent,
|
|
||||||
});
|
|
||||||
|
|
||||||
// onUpload(Number(progress.toFixed(2)) * 100);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
const request = await task.uploadAsync();
|
|
||||||
if (request.status !== 200) {
|
|
||||||
if (onError) onError(request.status);
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: JSON.stringify(documentInsert.errors),
|
|
||||||
message: request.body,
|
|
||||||
status: request.status,
|
|
||||||
mediaId,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (s3UploadResponse.status !== 200) {
|
||||||
|
console.log(
|
||||||
|
"Error uploading to cloudinary.",
|
||||||
|
s3UploadResponse.statusText,
|
||||||
|
s3UploadResponse
|
||||||
|
);
|
||||||
|
if (onError) onError(s3UploadResponse.statusText);
|
||||||
|
return { success: false, error: s3UploadResponse.statusText };
|
||||||
|
}
|
||||||
//debugger;
|
//debugger;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error uploading to S3", error.message, error.stack);
|
console.log("Error uploading to S3", error.message, error.stack);
|
||||||
if (onError) onError(error.message);
|
if (onError) onError(error.message);
|
||||||
|
Sentry.captureException(error);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
stack: error.stack,
|
stack: error.stack,
|
||||||
mediaId,
|
mediaId,
|
||||||
};
|
};
|
||||||
Sentry.captureException(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentInsert = await client.mutate({
|
const documentInsert = await client.mutate({
|
||||||
|
|||||||
Reference in New Issue
Block a user