From e5db0ee97acc6cbfb9f0209dd0dbd2e52e49ab7b Mon Sep 17 00:00:00 2001 From: tferns Date: Tue, 7 May 2024 07:39:21 +0100 Subject: [PATCH 1/2] FS-4355: Dynamically set file url on open method --- .../components/clientsidefileuploadfield.html | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/runner/src/server/plugins/engine/views/components/clientsidefileuploadfield.html b/runner/src/server/plugins/engine/views/components/clientsidefileuploadfield.html index d4c7817d4b..0fe682be48 100644 --- a/runner/src/server/plugins/engine/views/components/clientsidefileuploadfield.html +++ b/runner/src/server/plugins/engine/views/components/clientsidefileuploadfield.html @@ -240,7 +240,7 @@ {% endif %} const url = await getPreSignedUrl(file); - this.options.url = url; + file.uploadUrl = url; done(); }, // https://github.com/dropzone/dropzone/issues/590 @@ -388,6 +388,25 @@ return response.ok && (await response.json()).url } + const getFileByXHR = (xhr) => { + return (myDropzone.files || []).find(f => f.xhr === xhr); + } + + // Overrides XMLHttpRequest to inject a file-specific upload URL. This custom implementation enables Dropzone to + // upload to multiple URLs by linking an XHR instance to a file's pre-signed URL. The `open` method uses the + // pre-signed URL (set in `accept`) if available, ensuring each file has a unique upload destination. This + // workaround prevents race conditions from Dropzone's global URL configuration by associating each file with its + // XHR instance, avoiding mismatched or duplicate uploads across the event loop. + const OriginalXMLHttpRequest = window.XMLHttpRequest; + class CustomXMLHttpRequest extends OriginalXMLHttpRequest { + open(method, url, async = true, user = null, password = null) { + const file = getFileByXHR(this); + const openUrl = file && file.uploadUrl ? file.uploadUrl : url; + return super.open(method, openUrl, async, user, password); + } + } + window.XMLHttpRequest = CustomXMLHttpRequest; + {% endmacro %} From f7451a8c6d11974675675013fda36b11837dbecb Mon Sep 17 00:00:00 2001 From: Thomas <117724519+tferns@users.noreply.github.com> Date: Thu, 9 May 2024 14:36:51 +0100 Subject: [PATCH 2/2] Bump version --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 136ba90fa4..ddf7876946 100644 --- a/version +++ b/version @@ -1 +1 @@ -VERSION=0.1.258 +VERSION=0.1.269