Skip to content

Commit

Permalink
FIO-8208: Ensure that all file uploads alter the request options befo…
Browse files Browse the repository at this point in the history
…re sending the fetch requests.
  • Loading branch information
travist committed Feb 10, 2025
1 parent f8ba8e9 commit 5dba303
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/providers/storage/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function s3(formio) {
const { changeMessage } = multipart;
changeMessage('Completing AWS S3 multipart upload...');
const token = formio.getToken();
const response = await fetch(`${formio.formUrl}/storage/s3/multipart/complete`, {
const response = await XHR.fetch(`${formio.formUrl}/storage/s3/multipart/complete`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -117,7 +117,7 @@ function s3(formio) {
abortMultipartUpload(serverResponse) {
const { uploadId, key } = serverResponse;
const token = formio.getToken();
fetch(`${formio.formUrl}/storage/s3/multipart/abort`, {
XHR.fetch(`${formio.formUrl}/storage/s3/multipart/abort`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -134,7 +134,7 @@ function s3(formio) {
const start = i * partSize;
const end = (i + 1) * partSize;
const blob = i < urls.length ? file.slice(start, end) : file.slice(start);
const promise = fetch(urls[i], {
const promise = XHR.fetch(urls[i], {
method: 'PUT',
headers,
body: blob,
Expand Down
7 changes: 6 additions & 1 deletion src/providers/storage/xhr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _trim from 'lodash/trim';
import { Formio } from '../../Formio';
export const setXhrHeaders = (formio, xhr) => {
const { headers } = formio.options;
if (headers) {
Expand All @@ -21,12 +22,16 @@ const XHR = {
path(items) {
return items.filter(item => !!item).map(XHR.trim).join('/');
},
fetch(url, options) {
options = Formio.pluginAlter('requestOptions', options, url);
return fetch(url, options);
},
async upload(formio, type, xhrCallback, file, fileName, dir, progressCallback, groupPermissions, groupId, abortCallback, multipartOptions) {
// make request to Form.io server
const token = formio.getToken();
let response;
try {
response = await fetch(`${formio.formUrl}/storage/${type}`, {
response = await XHR.fetch(`${formio.formUrl}/storage/${type}`, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down

0 comments on commit 5dba303

Please sign in to comment.