Skip to content

Commit

Permalink
@uppy/xhr-upload: add support for arrays in metadata (#4431)
Browse files Browse the repository at this point in the history
Currently passing an array of `File` objects renders 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)
```
  • Loading branch information
stiig authored May 24, 2023
1 parent 0e3be10 commit 2b855ce
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/@uppy/xhr-upload/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ export default class XHRUpload extends BasePlugin {
: Object.keys(meta) // Send along all fields by default.

allowedMetaFields.forEach((item) => {
formData.append(item, meta[item])
if (Array.isArray(meta[item])) {
// 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])
}
})
}

Expand Down

0 comments on commit 2b855ce

Please sign in to comment.