Skip to content

Commit

Permalink
add polyfill and include token in abort and complete requests
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Oct 14, 2023
1 parent b577762 commit 9bfa323
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/providers/storage/s3.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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 })
});
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9bfa323

Please sign in to comment.