# Uploader ## Demos ### File upload Set the [`type`](#props-type) prop to `file` to use the file upload mode. [[ demo src="/demo/uploader/file.vue" ]] ### Image upload Set the [`type`](#props-type) prop to `image` to use the image upload mode. [[ demo src="/demo/uploader/image.vue" ]] ## API ### Props | Name | Type | Default | Description | | --- | --- | --- | --- | | ``ui`` | `string=` | - | [^ui] | | ``type`` | `string` | `'file'` | [^type] | | ``value`` | `Object | Array` | - | [^value] | | ``key-field`` | `string` | `'key'` | Used to specify a unique key for the file object, as a basis for correctly handling the order of the file list when the data changes. | | ``name`` | `string` | `'file'` | The `name` of native `` elements. | | ``action`` | `string` | - | Upload URL. | | ``headers`` | `Object` | `uploader.headers` | Extra [HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers). Can be [globally configured](#configs-uploader-headers). | | ``with-credentials`` | `boolean` | `true` | The same as the [`withCredentials`](https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/withCredentials) option of `XMLHttpRequest`. | | ``request-mode`` | `string` | `uploader.requestMode` | [^request-mode] | | ``iframe-mode`` | `string` | `uploader.iframeMode` | [^iframe-mode] | | ``callback-namespace`` | `string` | `uploader.callbackNamespace` | The namespace of the callback function when [`request-mode`](#props-request-mode) is `'iframe'` and `iframe-mode` is `'callback'`, will be placed under the `window` object. Can be [globally configured](#configs-uploader-callbackNamespace). | | ``data-type``| `string` | `'json'` | [^data-type] | | ``convert-response`` | `uploader.convertResponse` | - | [^convert-response] | | ``accept`` | `string` | - | The same as the [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/file#limiting_accepted_file_types) attribute of native `` elements. Works as an extra layer of validation on top of browsers' file filter. Will skip validation when MIME type doesn't match file extension, eg. `application/msword`. | | ``max-count`` | `number` | - | The maximum file count. | | ``max-size`` | `number | string` | - | The maximun size of a single file. When being a `number`, the unit will be `byte`. When being a `string`, units can be added after numbers, including `b` / `kb` / `mb` / `gb` / `tb`. | | ``payload`` | `Object` | - | The extra data payload to be sent together with the file. | | ``progress`` | `string` | `'text'` | [^progress] | | ``autoupload`` | `boolean` | `true` | Whether to start upload as soon as a file is selected. | | ``order`` | `string` | `asc` | [^order] | | ``upload`` | `function(Object, Object): function` | - | [^upload] | | ``controls`` | `function(Object, Array): Array` | - | [^controls] | ^^^ui Style variants. +++Enum values | Value | Description | | -- | -- | | `s` | Small. | | `m` | Medium. | +++ ^^^ ^^^type The type of the uploader. +++Enum values | Value | Description | | -- | -- | | `file` | File upload. | | `image` | Image upload. | +++ ^^^ ^^^value Returns an array of file objects when `multiple` is `true`. When `max-count` is set to a value greater than `1`, then `multiple` treated as `true`. The type of single file is `{name: string, src: string, ...}`, and fields added inside [`convert-response`](#props-convert-response). +++ ^^^ ^^^request-mode The request mode of the uploader. Can be [globally configured](#configs-uploader-request-mode). +++Enum values | Value | Description | | -- | -- | | `xhr` | Upload with `XMLHttpRequest`. | | `iframe` | Upload with `