From 46bb91604f629329c575315e304d19622d583f3e Mon Sep 17 00:00:00 2001 From: Vasiliy Matyushin <8639922+stiig@users.noreply.github.com> Date: Thu, 27 Apr 2023 14:24:55 +0500 Subject: [PATCH 1/4] Allow to upload multiple files in metaData Currently multiple files send as ``` field_from_form_for_files[]: [object File],[object File],[object File] ``` and it breaks default form behaviour, with this fix it works properly, like ``` field_from_form_for_files[]: (binary) field_from_form_for_files[]: (binary) field_from_form_for_files[]: (binary) ``` --- packages/@uppy/xhr-upload/src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/xhr-upload/src/index.js b/packages/@uppy/xhr-upload/src/index.js index b95d71f195..ea773b514d 100644 --- a/packages/@uppy/xhr-upload/src/index.js +++ b/packages/@uppy/xhr-upload/src/index.js @@ -171,7 +171,9 @@ export default class XHRUpload extends BasePlugin { : Object.keys(meta) // Send along all fields by default. allowedMetaFields.forEach((item) => { - formData.append(item, meta[item]) + Array.isArray(meta[item]) + ? meta[item].forEach(subItem => formData.append(item, subItem)) + : formData.append(item, meta[item]); }) } From 2ecd09083683a653d8841a6854fb963ea4c5bb92 Mon Sep 17 00:00:00 2001 From: stiig Date: Tue, 23 May 2023 18:52:20 +0500 Subject: [PATCH 2/4] Fix code style --- packages/@uppy/xhr-upload/src/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/@uppy/xhr-upload/src/index.js b/packages/@uppy/xhr-upload/src/index.js index ea773b514d..1fb475c54d 100644 --- a/packages/@uppy/xhr-upload/src/index.js +++ b/packages/@uppy/xhr-upload/src/index.js @@ -171,9 +171,11 @@ export default class XHRUpload extends BasePlugin { : Object.keys(meta) // Send along all fields by default. allowedMetaFields.forEach((item) => { - Array.isArray(meta[item]) - ? meta[item].forEach(subItem => formData.append(item, subItem)) - : formData.append(item, meta[item]); + if (Array.isArray(meta[item])) { + meta[item].forEach(subItem => formData.append(item, subItem)) + } else { + formData.append(item, meta[item]) + } }) } From c54b1ba107ff72c203cd5dc45ea27e4306ad6e8e Mon Sep 17 00:00:00 2001 From: stiig Date: Wed, 24 May 2023 18:32:39 +0500 Subject: [PATCH 3/4] add comment about param naming --- packages/@uppy/xhr-upload/src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@uppy/xhr-upload/src/index.js b/packages/@uppy/xhr-upload/src/index.js index 1fb475c54d..8b7fdb4d60 100644 --- a/packages/@uppy/xhr-upload/src/index.js +++ b/packages/@uppy/xhr-upload/src/index.js @@ -172,6 +172,8 @@ export default class XHRUpload extends BasePlugin { allowedMetaFields.forEach((item) => { if (Array.isArray(meta[item])) { + // In this case we don't need to transform `item` as a form value name, + // because it is already an array-like variable, for example `item[]` and it won't be overrided meta[item].forEach(subItem => formData.append(item, subItem)) } else { formData.append(item, meta[item]) From 7ee376eb7b7dabd10cbf25b0b1a8886aca970c50 Mon Sep 17 00:00:00 2001 From: Vasiliy Matyushin <8639922+stiig@users.noreply.github.com> Date: Wed, 24 May 2023 18:56:35 +0500 Subject: [PATCH 4/4] Update comment about param naming Co-authored-by: Antoine du Hamel --- packages/@uppy/xhr-upload/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@uppy/xhr-upload/src/index.js b/packages/@uppy/xhr-upload/src/index.js index 8b7fdb4d60..35a3aa15e3 100644 --- a/packages/@uppy/xhr-upload/src/index.js +++ b/packages/@uppy/xhr-upload/src/index.js @@ -172,8 +172,8 @@ export default class XHRUpload extends BasePlugin { allowedMetaFields.forEach((item) => { if (Array.isArray(meta[item])) { - // In this case we don't need to transform `item` as a form value name, - // because it is already an array-like variable, for example `item[]` and it won't be overrided + // In this case we don't transform `item` to add brackets, it's up to + // the user to add the brackets so it won't be overridden. meta[item].forEach(subItem => formData.append(item, subItem)) } else { formData.append(item, meta[item])