Corrected imgproxy uploading.

This commit is contained in:
Patrick Fic
2025-06-02 10:26:17 -07:00
parent 00002ed0f5
commit ed6c98958c

View File

@@ -145,7 +145,7 @@ export const uploadToImgproxy = async (
},
transformRequest: [(data) => data], //Dave had this magical solution because Axios makes no sense.
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 {
// const s3UploadResponse = await cleanAxios.put(
// preSignedUploadUrlToS3,
// file,
// options
// );
const task = FileSystem.createUploadTask(
const s3UploadResponse = await cleanAxios.put(
preSignedUploadUrlToS3,
imageData.localUri,
{
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);
}
file,
options
);
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;
} catch (error) {
console.log("Error uploading to S3", error.message, error.stack);
if (onError) onError(error.message);
Sentry.captureException(error);
return {
success: false,
error: error.message,
stack: error.stack,
mediaId,
};
Sentry.captureException(error);
}
const documentInsert = await client.mutate({