IO-3092 Move upload to use expo upload instead of axios for proper status reporting.

This commit is contained in:
Patrick Fic
2025-02-28 10:59:35 -08:00
parent ca93c0900c
commit b2869b9fac
2 changed files with 86 additions and 42 deletions

View File

@@ -6,6 +6,8 @@ import { client } from "../graphql/client";
import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries";
import { axiosAuthInterceptorId } from "./CleanAxios";
import { splitClient } from "../components/screen-main/screen-main.component";
import * as FileSystem from "expo-file-system";
//Context: currentUserEmail, bodyshop, jobid, invoiceid
//Required to prevent headers from getting set and rejected from Cloudinary.
@@ -143,15 +145,57 @@ export const uploadToImgproxy = async (
});
try {
const s3UploadResponse = await cleanAxios.put(
preSignedUploadUrlToS3,
file,
options
);
// const s3UploadResponse = await cleanAxios.put(
// preSignedUploadUrlToS3,
// file,
// options
// );
const task = FileSystem.createUploadTask(
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);
}
);
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,
};
}
//debugger;
} catch (error) {
console.log("Error uploading to S3", error.message, error.stack);
if (onError) onError(error.message);
return {
success: false,
error: error.message,
stack: error.stack,
mediaId,
};
Sentry.Native.captureException(error);
}