Przeglądaj źródła

xhr: change default name depending on whether `bundle` is set (#2933)

* temporarily add cheerio-select-tmp to devDependencies to fix tests

* xhr: change default name depending on whether `bundle` is set

Fixes: https://github.com/transloadit/uppy/issues/782

* Update docs
Antoine du Hamel 3 lat temu
rodzic
commit
6efecf6f0f

+ 1 - 1
BACKLOG.md

@@ -54,7 +54,7 @@ PRs are welcome! Please do open an issue to discuss first if it's a big feature,
 - [ ] transloadit: remove `UPPY_SERVER` constant (@mifi)
 - [ ] tus: set the `limit` option to a sensible default, like 5 (10?) (@arturi)
 - [ ] xhr: set the `limit` option to a sensible default, like 5 (10?) (@arturi)
-- [ ] xhr: change default name depending on whether `bundle` is set `files[]` (`true`) vs `file` (default) (#782) (@aduh95)
+- [x] xhr: change default name depending on whether `bundle` is set `files[]` (`true`) vs `file` (default) (#782) (@aduh95)
 - [ ] providers: allow changing provider name title through locale? https://github.com/transloadit/uppy/issues/2279 (@goto-bus-stop)
 - [ ] tus: remove `autoRetry` option (throw error at runtime if it is explicitly given) (@aduh95)
 

+ 1 - 1
packages/@uppy/xhr-upload/src/index.js

@@ -61,7 +61,7 @@ module.exports = class XHRUpload extends Plugin {
     // Default options
     const defaultOptions = {
       formData: true,
-      fieldName: 'files[]',
+      fieldName: opts.bundle ? 'files[]' : 'file',
       method: 'post',
       metaFields: null,
       responseUrlFieldName: 'url',

+ 4 - 2
website/src/docs/xhrupload.md

@@ -61,9 +61,11 @@ This works similarly to using a `<form>` element with an `<input type="file">` f
 When set to `true`, file metadata is also sent to the endpoint as separate form fields.
 When set to `false`, only the file contents are sent.
 
-### `fieldName: 'files[]'`
+### `fieldName: 'file'`
 
-When [`formData`](#formData-true) is set to true, this is used as the form field name for the file to be uploaded.
+When [`formData`](#formData-true) is set to true, this is used as the form field
+name for the file to be uploaded. It defaults to `'files[]'` if `bundle` option
+is set to `true`, otherwise it defaults to `'file'`.
 
 ### `metaFields: null`