From b6e9c7aabf6d7696494a1fb4d8ddd398f2db90fc Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Mon, 22 Nov 2021 15:33:32 +0800 Subject: [PATCH] TUS: handle URL removal on 4xx errors ## Issue The TUS client automatically removes the upload fingerprint whenever there is a 4xx error. When we try to resume later, we couldn't find the the fingerprint and ended up creating a new upload ID. ## Changes Since we are also storing the uploadUrl ourselves, provided that to override the tus client's default behavior of restarting a new session on 4xx errors. --- web/setup/publish-v2.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/setup/publish-v2.js b/web/setup/publish-v2.js index c71e543bd..e5a7cc9db 100644 --- a/web/setup/publish-v2.js +++ b/web/setup/publish-v2.js @@ -48,8 +48,18 @@ export function makeResumableUploadRequest( id: new Date().getTime(), }); + const urlOptions = {}; + if (params.uploadUrl) { + // Resuming from previous upload. TUS clears the resume fingerprint on any + // 4xx error, so we need to use the fixed URL mode instead. + urlOptions.uploadUrl = params.uploadUrl; + } else { + // New upload, so use `endpoint`. + urlOptions.endpoint = RESUMABLE_ENDPOINT; + } + const uploader = new tus.Upload(file, { - endpoint: RESUMABLE_ENDPOINT, + ...urlOptions, chunkSize: UPLOAD_CHUNK_SIZE_BYTE, retryDelays: [0, 5000, 10000, 15000], parallelUploads: 1,