Media
FileUpload
A file input drawn as a button, a drop zone and a queue, checking type, size and count, with upload progress.
WAI-ARIA tested
Import
main.ts
import { FileUpload } from '@vitral/vue';Advanced
Drag images here, up to five, 1 MB each.
Basic
API
Read from packages/vue/src/components/FileUpload/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| mode | 'advanced' | 'basic' | `advanced` (the default): a drop zone, a queue and upload buttons. `basic`: one button. |
| name | string | The form field name the files are sent under. Defaults to `'files[]'`. |
| url | string | Where the files are posted. Leave it out with `customUpload`. |
| multiple | boolean | — |
| accept | string | The `accept` attribute: `image/*`, `.pdf`… Files that do not match are refused with a message. |
| maxFileSize | number | In bytes. Larger files are refused with a message. |
| fileLimit | number | How many files may be queued and uploaded in all. |
| disabled | boolean | — |
| auto | boolean | Upload as soon as files are chosen. |
| customUpload | boolean | Emit `uploader` with the files instead of posting them. |
| withCredentials | boolean | — |
| requestPerFile | boolean | Post each file in a request of its own, each with its own progress bar; a file leaves the queue as soon as its request succeeds. By default all the queued files go in one request. |
| chooseLabel | string | — |
| uploadLabel | string | — |
| cancelLabel | string | — |
| showUploadButton | boolean | Defaults to true. |
| showCancelButton | boolean | Defaults to true. |
| invalidFileTypeMessage | string | `{name}`, `{types}`. Defaults to the locale's. |
| invalidFileSizeMessage | string | `{name}`, `{size}`. Defaults to the locale's. |
| invalidFileLimitMessage | string | `{limit}`. Defaults to the locale's. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| select | event: FileUploadEvent & { originalEvent: Event } | — |
| before-upload | event: { xhr: XMLHttpRequest; formData: FormData } | — |
| progress | event: { originalEvent: ProgressEvent; progress: number; file?: File; fileProgress?: number } | `progress` is the whole upload's; with `requestPerFile`, `file` and `fileProgress` say which request moved. |
| upload | event: FileUploadEvent & { xhr: XMLHttpRequest } | — |
| error | event: FileUploadEvent & { xhr: XMLHttpRequest } | — |
| uploader | event: FileUploadEvent | With `customUpload`: upload these yourself. |
| remove | event: { file: File; files: File[] } | — |
| clear | — | — |
Slots
| Name | Slot props | Description |
|---|---|---|
| header | (props: { files: File[]; chooseCallback: () => void; uploadCallback: () => void; clearCallback: () => void }) | Extra content in the toolbar. |
| content | (props: { files: File[]; uploadedFiles: File[]; removeFileCallback: (index: number) => void; progress: number; messages: string[] }) | Replaces the queue. |
| empty | — | Shown while the queue is empty. |