# Uploader ### Intro Used to upload local pictures or files to the server. ### Install ```js import { createApp } from 'vue' import { Uploader } from '@nutui/nutui' const app = createApp() app.use(Uploader) ``` ### Basic Usage :::demo ```vue ``` ::: ### Upload status :::demo ```vue ``` ::: ### Basic usage - upload list display :::demo ```vue ``` ::: ### Custom upload style :::demo ```vue ``` ::: ### Custom upload uses default progress bar :::demo ```vue ``` ::: ### Directly activate the camera (effective on the mobile terminal) :::demo ```vue ``` ::: ### Limit the number of uploads to 5 :::demo ```vue ``` ::: ### Limit upload size (up to 50kb per file) :::demo ```vue ``` ::: ### Image compression (handled in the beforeupload hook) :::demo ```vue ``` ::: ### Custom data FormData , headers :::demo ```vue ``` ::: ### Customize XHR upload(before-xhr-upload) :::demo ```vue ``` ::: ### Once the file is selected, manually perform the upload via the button :::demo ```vue ``` ::: ### Disabled state :::demo ```vue ``` ::: ## API ### Props | Attribute | Description | Type | Default | | --- | --- | --- | --- | | auto-upload | Whether to upload the file immediately after selecting it, if false, you need to manually execute the ref submit method to upload | boolean | `true` | | name | The name of the `input` tag `name`, the file parameter name sent to the background | string | `"file"` | | url | The interface address of the upload server | string | - | | v-model:file-list | List of uploaded files by default | FileItem[] | `[]` | | is-preview | Whether to display the preview image after the upload is successful | boolean | true | | is-deletable | Whether to display the delete button | boolean | `true` | | method | The http method of upload request | string | `"post"` | | list-type | Built-in stylesheets, support for three types: `picture`、`list` | string | "picture" | | capture | Capture, can be set to [camera](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#htmlattrdefcapture),turn on the camera directly | string | false | | maximize | You can set the maximum upload file size (bytes) | number \| string | `Number.MAX_VALUE` | | maximum | File upload limit | number \| string | `1` | | clear-input | Whether to clear the `input` content, set to `true` to support repeated selection and upload of the same file | boolean | `true` | | accept | File types that can be accepted. See [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) | string | \* | | headers | Set request headers | object | `{} ` | | data | Uploading extra params or function which can return uploading extra params | object | {} | | upload-icon-size | Upload area [icon size] (#/en-US/component/icon) size, such as `20px` `2em` `2rem` | string \| object | - | | xhr-state | The success status (status) value of the interface response | number | `200` | | with-credentials | The ajax upload with cookie sent | boolean | `false` | | multiple | Whether to support multiple file selection | boolean | `false` | | disabled | Whether to disable file upload | boolean | `false` | | timeout | timeout, in milliseconds | number \| string | `1000 * 30 ` | | before-upload | Hook before reading the file, return false to stop reading the file, can return Promise | Function | `null` | | before-xhr-upload | Customize the method when uploading XHR | Function(xhr,option) | `null` | | before-delete | Hook before delete the file, return false to stop reading the file, can return Promise | Function(file,fileList): boolean `丨Promise` | - | ### FileItem | Attribute | Description | Default | | --- | --- | --- | | status | File status value, optional `ready`,`uploading`,`success`,`error` | `ready` | | uid | Unique ID of the file | `new Date().getTime().toString()` | | name | File name | - | | url | File path | - | | type | File type | `"image/jpeg" ` | | formData | Upload the required data | `new FormData()` | | percentage | Upload percentage | `0` | ### Events | Event | Description | Arguments | | --- | --- | --- | | start | File upload starts | `options` | | progress | The progress of the file upload | `{event,option,percentage}` | | oversize | Triggered when the file size exceeds the limit | `files` | | success | Uploaded successfully | `{responseText,option,fileItem}` | | failure | Upload failed | `{responseText,option,fileItem}` | | change | The state when the uploaded file changes | `{fileList,event}` | | delete | File delete event | `{files,fileList,index}` | | file-item-click | Click to trigger after the file is uploaded successfully | `{fileItem}` | ### Uploader Slots | Name | Description | | --- | --- | | default | Default slot | | upload-icon | Custom Uploader Button Center `icon` | | delete-icon | Custom Right Delete Button | ### Methods Use [ref](https://vuejs.org/guide/essentials/template-refs.html#template-refs) to get Uploader instance and call instance methods. | Name | Description | Arguments | Return value | | --- | --- | --- | --- | | submit | Manual upload mode, perform upload operation | - | - | | clearUploadQueue | Empty the selected file queue (this method is generally used when uploading in manual mode) | index | - | ## Theming ### CSS Variables The component provides the following CSS variables, which can be used to customize styles. Please refer to [ConfigProvider component](#/en-US/component/configprovider). | Name | Default Value | | --- | --- | | --nut-uploader-picture-width | _100px_ | | --nut-uploader-picture-height | _100px_ | | --nut-uploader-background | _#f7f8fa_ |