Improved document uploads & remove console logs.
This commit is contained in:
@@ -16,11 +16,8 @@ export const handleUpload = async (ev, context) => {
|
||||
const { bodyshop, jobId } = context;
|
||||
|
||||
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(
|
||||
/\.[^/.]+$/,
|
||||
""
|
||||
@@ -69,12 +66,14 @@ export const uploadToCloudinary = async (
|
||||
: "incoming_upload";
|
||||
|
||||
//Get the signed url.
|
||||
|
||||
let signedURLResponse;
|
||||
try {
|
||||
signedURLResponse = await axios.post(`${env.API_URL}/media/sign`, {
|
||||
public_id: public_id,
|
||||
tags: tags,
|
||||
timestamp: timestamp,
|
||||
|
||||
upload_preset: upload_preset,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -90,24 +89,23 @@ export const uploadToCloudinary = async (
|
||||
}
|
||||
|
||||
//Build request to end to cloudinary.
|
||||
|
||||
var signature = signedURLResponse.data;
|
||||
var options = {
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" },
|
||||
onUploadProgress: (e) => {
|
||||
if (onProgress) onProgress({ percent: e.loaded / e.total });
|
||||
if (onProgress)
|
||||
onProgress({ percent: e.loaded / e.total, loaded: e.loaded });
|
||||
},
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("file", {
|
||||
uri: imageData.localUri,
|
||||
type: fileType,
|
||||
name: file.data.name,
|
||||
});
|
||||
|
||||
formData.append("upload_preset", upload_preset);
|
||||
|
||||
formData.append("api_key", env.REACT_APP_CLOUDINARY_API_KEY);
|
||||
formData.append("public_id", public_id);
|
||||
formData.append("tags", tags);
|
||||
@@ -190,6 +188,7 @@ export const uploadToCloudinary = async (
|
||||
mediaId,
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true, mediaId };
|
||||
};
|
||||
|
||||
@@ -202,3 +201,14 @@ export function DetermineFileType(filetype) {
|
||||
|
||||
return "auto";
|
||||
}
|
||||
|
||||
export function formatBytes(a, b = 2) {
|
||||
if (0 === a || !a) return "0 Bytes";
|
||||
const c = 0 > b ? 0 : b,
|
||||
d = Math.floor(Math.log(a) / Math.log(1024));
|
||||
return (
|
||||
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
|
||||
" " +
|
||||
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user