Improved uploads & handling for temp jobs. IO-399 IO-398 IO-69
This commit is contained in:
@@ -14,6 +14,7 @@ export const handleUpload = async (ev, context) => {
|
||||
const { bodyshop, jobId } = context;
|
||||
|
||||
const newFile = await (await fetch(ev.uri)).blob();
|
||||
let extension = ev.uri.split(".").pop();
|
||||
|
||||
let key = `${bodyshop.id}/${jobId}/${newFile.data.name.replace(
|
||||
/\.[^/.]+$/,
|
||||
@@ -21,6 +22,7 @@ export const handleUpload = async (ev, context) => {
|
||||
)}`;
|
||||
return uploadToCloudinary(
|
||||
key,
|
||||
extension,
|
||||
newFile.type,
|
||||
newFile,
|
||||
onError,
|
||||
@@ -32,6 +34,7 @@ export const handleUpload = async (ev, context) => {
|
||||
|
||||
export const uploadToCloudinary = async (
|
||||
key,
|
||||
extension,
|
||||
fileType,
|
||||
file,
|
||||
onError,
|
||||
@@ -56,15 +59,19 @@ export const uploadToCloudinary = async (
|
||||
tagsArray ? tagsArray.map((tag) => `${tag},`) : ""
|
||||
}`;
|
||||
// let eager = process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS;
|
||||
console.log("fileType", fileType);
|
||||
const upload_preset = fileType.startsWith("video")
|
||||
? "incoming_upload_video"
|
||||
: "incoming_upload";
|
||||
|
||||
//Get the signed url.
|
||||
let signedURLResponse;
|
||||
try {
|
||||
signedURLResponse = await axios.post("https://api.imex.online/media/sign", {
|
||||
signedURLResponse = await axios.post(`${env.API_URL}/media/sign`, {
|
||||
public_id: public_id,
|
||||
tags: tags,
|
||||
timestamp: timestamp,
|
||||
upload_preset: "incoming_upload",
|
||||
upload_preset: upload_preset,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("ERROR GETTING SIGNED URL", error);
|
||||
@@ -94,7 +101,7 @@ export const uploadToCloudinary = async (
|
||||
name: file.data.name,
|
||||
});
|
||||
|
||||
formData.append("upload_preset", "incoming_upload");
|
||||
formData.append("upload_preset", upload_preset);
|
||||
|
||||
formData.append("api_key", env.REACT_APP_CLOUDINARY_API_KEY);
|
||||
formData.append("public_id", public_id);
|
||||
@@ -106,7 +113,9 @@ export const uploadToCloudinary = async (
|
||||
let cloudinaryUploadResponse;
|
||||
try {
|
||||
cloudinaryUploadResponse = await cleanAxios.post(
|
||||
`${env.REACT_APP_CLOUDINARY_ENDPOINT}/upload`,
|
||||
`${env.REACT_APP_CLOUDINARY_ENDPOINT_API}/${DetermineFileType(
|
||||
fileType
|
||||
)}/upload`,
|
||||
formData,
|
||||
{
|
||||
...options,
|
||||
@@ -139,6 +148,7 @@ export const uploadToCloudinary = async (
|
||||
key: key,
|
||||
billid: billId,
|
||||
type: fileType,
|
||||
extension: extension,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -168,3 +178,14 @@ export const uploadToCloudinary = async (
|
||||
}
|
||||
return { success: true };
|
||||
};
|
||||
|
||||
export function DetermineFileType(filetype) {
|
||||
console.log("Checking Type", filetype, filetype.startsWith("video"));
|
||||
if (!filetype) return "auto";
|
||||
else if (filetype.startsWith("image")) return "image";
|
||||
else if (filetype.startsWith("video")) return "video";
|
||||
else if (filetype.startsWith("application/pdf")) return "image";
|
||||
else if (filetype.startsWith("application")) return "raw";
|
||||
|
||||
return "auto";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user