Resolve upload issues.

This commit is contained in:
Patrick Fic
2021-06-10 10:46:12 -07:00
parent 04e3a77312
commit b857a9bfbd
6 changed files with 118 additions and 70 deletions

View File

@@ -152,40 +152,25 @@ export function UploadProgress({
}
//Sequentially await the proms.
for (const p of data) {
let filename;
filename = p.filename || p.uri.split("/").pop();
await handleUpload(
{
filename,
mediaId: p.id,
onError: handleOnError,
onProgress: ({ percent, loaded }) =>
handleOnProgress(p.id, percent, loaded),
onSuccess: () => handleOnSuccess(p.id),
},
{
bodyshop: bodyshop,
jobId: selectedCameraJobId !== "temp" ? selectedCameraJobId : null,
uploaded_by: currentUser.email,
photo: p,
}
);
//Set the state to mark that it's done.
setProgress((progress) => ({
...progress,
action: null,
speed: 0,
files: {
...progress.files,
[p.id]: {
...progress.files[p.id],
action: null,
},
},
}));
for (var i = 0; i < data.length + 4; i = i + 4) {
console.log("i :>> ", i);
let proms = [];
if (data[i]) {
proms.push(CreateUploadProm(data[i]));
}
if (data[i + 1]) {
proms.push(CreateUploadProm(data[i + 1]));
}
if (data[i + 2]) {
proms.push(CreateUploadProm(data[i + 2]));
}
if (data[i + 3]) {
proms.push(CreateUploadProm(data[i + 3]));
}
console.log("Proms Length", proms.length);
await Promise.all(proms);
console.log("Await done.");
}
if (deleteAfterUpload) {
@@ -208,6 +193,43 @@ export function UploadProgress({
forceRerender();
};
const CreateUploadProm = async (p) => {
let filename;
filename = p.filename || p.uri.split("/").pop();
console.log("Start upping.", p.id);
await handleUpload(
{
filename,
mediaId: p.id,
onError: handleOnError,
onProgress: ({ percent, loaded }) =>
handleOnProgress(p.id, percent, loaded),
onSuccess: () => handleOnSuccess(p.id),
},
{
bodyshop: bodyshop,
jobId: selectedCameraJobId !== "temp" ? selectedCameraJobId : null,
uploaded_by: currentUser.email,
photo: p,
}
);
console.log("Done upping.", p.id);
//Set the state to mark that it's done.
setProgress((progress) => ({
...progress,
action: null,
speed: 0,
files: {
...progress.files,
[p.id]: {
...progress.files[p.id],
action: null,
},
},
}));
};
return (
<Modal
visible={progress.uploadInProgress}