Vitral 0.2.18
Media

FileUpload

A file input drawn as a button, a drop zone and a queue, checking type, size and count, with upload progress.

Import

main.ts
import { FileUpload } from '@vitral/vue';

Advanced

Drag images here, up to five, 1 MB each.
<script setup lang="ts">import { FileUpload } from '@vitral/vue';import { ref } from 'vue'; const status = ref(''); // There is no server behind the docs: the demo takes the files itself and pretends.function pretend({ files }: { files: File[] }) {    status.value = `${files.map((f) => f.name).join(', ')}: received here, and nothing left your browser.`;}</script> <template>    <FileUpload multiple accept="image/*" :max-file-size="1000000" :file-limit="5" custom-upload @uploader="pretend">        <template #empty>            <span>Drag images here, up to five, 1 MB each.</span>        </template>    </FileUpload>    <small style="color: var(--vt-text-muted-color)" aria-live="polite">{{ status }}</small></template>

Basic

<script setup lang="ts">import { FileUpload } from '@vitral/vue';import { ref } from 'vue'; const status = ref(''); // There is no server behind the docs: the demo takes the file itself and pretends.function pretend({ files }: { files: File[] }) {    status.value = `${files.map((f) => f.name).join(', ')}: received here, and nothing left your browser.`;}</script> <template>    <FileUpload mode="basic" accept=".pdf" choose-label="Choose a PDF" custom-upload auto @uploader="pretend" />    <small style="color: var(--vt-text-muted-color)" aria-live="polite">{{ status }}</small></template>

API

Read from packages/vue/src/components/FileUpload/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
mode 'advanced' | 'basic'`advanced` (the default): a drop zone, a queue and upload buttons. `basic`: one button.
name stringThe form field name the files are sent under. Defaults to `'files[]'`.
url stringWhere the files are posted. Leave it out with `customUpload`.
multiple boolean—
accept stringThe `accept` attribute: `image/*`, `.pdf`… Files that do not match are refused with a message.
maxFileSize numberIn bytes. Larger files are refused with a message.
fileLimit numberHow many files may be queued and uploaded in all.
disabled boolean—
auto booleanUpload as soon as files are chosen.
customUpload booleanEmit `uploader` with the files instead of posting them.
withCredentials boolean—
requestPerFile booleanPost 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 booleanDefaults to true.
showCancelButton booleanDefaults 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

EventPayloadDescription
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: FileUploadEventWith `customUpload`: upload these yourself.
remove event: { file: File; files: File[] }—
clear ——

Slots

NameSlot propsDescription
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.