From 2fc79b4bab7e0329a8048f56ff2cff68c275fccf Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 1 Jul 2022 17:56:35 +0200 Subject: [PATCH 1/2] Improve robustness of tus upload and calculation of progress We now don't let the upload fail at all and instead retry indefinitely. The progress report is also more accurate as we only report the progress of individual chunks that have been confirmed by the server. --- client/src/utils/uploadbox.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/client/src/utils/uploadbox.js b/client/src/utils/uploadbox.js index f7107487ccf..eed87bca585 100644 --- a/client/src/utils/uploadbox.js +++ b/client/src/utils/uploadbox.js @@ -39,16 +39,25 @@ function tusUpload(data, index, tusEndpoint, cnf) { console.debug(`Starting chunked upload for ${file.name} [chunkSize=${chunkSize}].`); const upload = new tus.Upload(file, { endpoint: tusEndpoint, + retryDelays: [0, 3000, 10000], fingerprint: buildFingerprint(cnf), chunkSize: chunkSize, metadata: data.payload, - onError: function (error) { - console.log("Failed because: " + error); - cnf.error(error); + onError: function (err) { + const status = err.originalResponse?.getStatus(); + if (status == 403) { + console.error(`Failed because of missing authorization: ${err}`); + cnf.error(error); + } else { + // 🎵 Never gonna give you up 🎵 + console.log(`Failed because: ${err}\n, will retry in 10 seconds`); + + setTimeout(() => startTusUpload(upload), 10000); + } }, - onProgress: function (bytesUploaded, bytesTotal) { - var percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2); - console.log(bytesUploaded, bytesTotal, percentage + "%"); + onChunkComplete: function (chunkSize, bytesAccepted, bytesTotal) { + const percentage = ((bytesAccepted / bytesTotal) * 100).toFixed(2); + console.log(bytesAccepted, bytesTotal, percentage + "%"); cnf.progress(percentage); }, onSuccess: function () { @@ -62,6 +71,10 @@ function tusUpload(data, index, tusEndpoint, cnf) { tusUpload(data, index + 1, tusEndpoint, cnf); }, }); + startTusUpload(upload); +} + +function startTusUpload(upload) { // Check if there are any previous uploads to continue. upload.findPreviousUploads().then(function (previousUploads) { // Found previous uploads so we select the first one. From 4793bbc88ba15e42ae414154e1bc6aa153788c20 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Sat, 2 Jul 2022 07:45:53 -0400 Subject: [PATCH 2/2] Minor rename in uploadbox to use err var --- client/src/utils/uploadbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/utils/uploadbox.js b/client/src/utils/uploadbox.js index eed87bca585..ed458b3d7c5 100644 --- a/client/src/utils/uploadbox.js +++ b/client/src/utils/uploadbox.js @@ -47,7 +47,7 @@ function tusUpload(data, index, tusEndpoint, cnf) { const status = err.originalResponse?.getStatus(); if (status == 403) { console.error(`Failed because of missing authorization: ${err}`); - cnf.error(error); + cnf.error(err); } else { // 🎵 Never gonna give you up 🎵 console.log(`Failed because: ${err}\n, will retry in 10 seconds`);