diff --git a/package.json b/package.json index 44d0f40782..9de818ead2 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "@formio/core": "1.3.0-rc.16", "@formio/text-mask-addons": "^3.8.0-formio.2", "@formio/vanilla-text-mask": "^5.1.1-formio.1", + "abortcontroller-polyfill": "^1.7.5", "autocompleter": "^8.0.4", "bootstrap": "^5.3.0", "browser-cookies": "^1.2.0", diff --git a/src/providers/storage/s3.js b/src/providers/storage/s3.js index 2ae8acd0cc..210ddb8b58 100644 --- a/src/providers/storage/s3.js +++ b/src/providers/storage/s3.js @@ -1,5 +1,7 @@ import XHR from './xhr'; import { withRetries } from './util'; + +const AbortController = window.AbortController || require('abortcontroller-polyfill/dist/cjs-ponyfill'); function s3(formio) { return { async uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback, multipartOptions) { @@ -80,10 +82,12 @@ function s3(formio) { async completeMultipartUpload(serverResponse, parts, multipart) { const { changeMessage } = multipart; changeMessage('Completing AWS S3 multipart upload...'); + const token = formio.getToken(); const response = await fetch(`${formio.formUrl}/storage/s3/multipart/complete`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + ...(token ? { 'x-jwt-token': token } : {}) }, body: JSON.stringify({ parts, uploadId: serverResponse.uploadId, key: serverResponse.key }) }); @@ -99,13 +103,15 @@ function s3(formio) { }, abortMultipartUpload(serverResponse) { const { uploadId, key } = serverResponse; + const token = formio.getToken(); fetch(`${formio.formUrl}/storage/s3/multipart/abort`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + ...(token ? { 'x-jwt-token': token } : {}) }, body: JSON.stringify({ uploadId, key }) - }); + }).catch((err) => console.error('Error while aborting multipart upload:', err)); }, uploadParts(file, urls, headers, partSize, multipart, abortSignal) { const { changeMessage, progressCallback } = multipart; diff --git a/yarn.lock b/yarn.lock index d3822a5834..5597f5e203 100644 --- a/yarn.lock +++ b/yarn.lock @@ -792,6 +792,11 @@ abbrev@^1.0.0: resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== +abortcontroller-polyfill@^1.7.5: + version "1.7.5" + resolved "https://registry.yarnpkg.com/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.5.tgz#6738495f4e901fbb57b6c0611d0c75f76c485bed" + integrity sha512-JMJ5soJWP18htbbxJjG7bG6yuI6pRhgJ0scHHTfkUjf6wjP912xZWvM+A4sJK3gqd9E8fcPbDnOefbA9Th/FIQ== + accepts@~1.3.4: version "1.3.8" resolved "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e"