FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.
import FileUpload from 'primevue/fileupload';
FileUpload basic mode provides a simpler UI as an alternative to default advanced mode.
<FileUpload mode="basic" name="demo[]" url="/api/upload" accept="image/*" :maxFileSize="1000000" @upload="onUpload" />
When auto property is enabled, a file gets uploaded instantly after selection.
<FileUpload mode="basic" name="demo[]" url="/api/upload" accept="image/*" :maxFileSize="1000000" @upload="onUpload" :auto="true" chooseLabel="Browse" />
FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.
Drag and drop files to here to upload.
<FileUpload name="demo[]" url="/api/upload" @upload="onAdvancedUpload($event)" :multiple="true" accept="image/*" :maxFileSize="1000000">
<template #empty>
<p>Drag and drop files to here to upload.</p>
</template>
</FileUpload>
Uploader UI can be customized with templating.
Drag and drop files to here to upload.
<FileUpload name="demo[]" url="/api/upload" @upload="onTemplatedUpload($event)" :multiple="true" accept="image/*" :maxFileSize="1000000" @select="onSelectedFiles">
<template #header="{ chooseCallback, uploadCallback, clearCallback, files }">
<div class="flex flex-wrap justify-content-between align-items-center flex-1 gap-2">
<div class="flex gap-2">
<Button @click="chooseCallback()" icon="pi pi-images" rounded outlined></Button>
<Button @click="uploadEvent(uploadCallback)" icon="pi pi-cloud-upload" rounded outlined severity="success" :disabled="!files || files.length === 0"></Button>
<Button @click="clearCallback()" icon="pi pi-times" rounded outlined severity="danger" :disabled="!files || files.length === 0"></Button>
</div>
<ProgressBar :value="totalSizePercent" :showValue="false" :class="['md:w-20rem h-1rem w-full md:ml-auto', { 'exceeded-progress-bar': totalSizePercent > 100 }]"
><span class="white-space-nowrap">{{ totalSize }}B / 1Mb</span></ProgressBar
>
</div>
</template>
<template #content="{ files, uploadedFiles, removeUploadedFileCallback, removeFileCallback }">
<div v-if="files.length > 0">
<h5>Pending</h5>
<div class="flex flex-wrap p-0 sm:p-5 gap-5">
<div v-for="(file, index) of files" :key="file.name + file.type + file.size" class="card m-0 px-6 flex flex-column border-1 surface-border align-items-center gap-3">
<div>
<img role="presentation" :alt="file.name" :src="file.objectURL" width="100" height="50" />
</div>
<span class="font-semibold">{{ file.name }}</span>
<div>{{ formatSize(file.size) }}</div>
<Badge value="Pending" severity="warning" />
<Button icon="pi pi-times" @click="onRemoveTemplatingFile(file, removeFileCallback, index)" outlined rounded severity="danger" />
</div>
</div>
</div>
<div v-if="uploadedFiles.length > 0">
<h5>Completed</h5>
<div class="flex flex-wrap p-0 sm:p-5 gap-5">
<div v-for="(file, index) of uploadedFiles" :key="file.name + file.type + file.size" class="card m-0 px-6 flex flex-column border-1 surface-border align-items-center gap-3">
<div>
<img role="presentation" :alt="file.name" :src="file.objectURL" width="100" height="50" />
</div>
<span class="font-semibold">{{ file.name }}</span>
<div>{{ formatSize(file.size) }}</div>
<Badge value="Completed" class="mt-3" severity="success" />
<Button icon="pi pi-times" @click="removeUploadedFileCallback(index)" outlined rounded severity="danger" />
</div>
</div>
</div>
</template>
<template #empty>
<div class="flex align-items-center justify-content-center flex-column">
<i class="pi pi-cloud-upload border-2 border-circle p-5 text-8xl text-400 border-400" />
<p class="mt-4 mb-0">Drag and drop files to here to upload.</p>
</div>
</template>
</FileUpload>
Uploading implementation can be overridden by enabling customUpload property and defining a custom uploader handler event.
<FileUpload mode="basic" name="demo[]" url="/api/upload" accept="image/*" customUpload @uploader="customBase64Uploader" />
FileUpload uses a hidden native input element with type="file" for screen readers.
Interactive elements of the uploader are buttons, visit the Button accessibility section for more information.
API defines helper props, events and others for the PrimeVue File Upload module.
FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.
Defines valid properties in FileUpload component.
name | parameters | returnType | description | |
---|---|---|---|---|
select | event: FileUploadSelectEvent | void | Callback to invoke when files are selected. | |
before-upload | event: FileUploadBeforeUploadEvent | void | Callback to invoke before file upload begins to customize the request such as post parameters before the files. | |
progress | event: FileUploadProgressEvent | void | Callback to invoke when files are being uploaded. | |
upload | event: FileUploadUploadEvent | void | Callback to invoke when file upload is complete. | |
uploader | event: FileUploadUploaderEvent | void | Callback to invoke to implement a custom upload. | |
error | event: FileUploadErrorEvent | void | Callback to invoke if file upload fails. | |
before-send | event: FileUploadBeforeSendEvent | void | Callback to invoke before file send begins to customize the request such as adding headers. | |
clear | void | Callback to invoke when files in queue are removed without uploading. | ||
remove | event: FileUploadRemoveEvent | void | Callback to invoke when a singe file is removed from the list. | |
removeUploadedFile | event: FileUploadRemoveUploadedFile | void | Callback to invoke when a single uploaded file is removed from the uploaded file list. |
Defines valid slots in FileUpload slots.
Defines the custom events used by the component's emit.
Custom select event.
See select
Custom before upload event.
See before-upload
Custom progress event.
See progress
Custom upload event.
See upload
name | type | description |
---|---|---|
xhr | XMLHttpRequest | XmlHttpRequest instance. |
files | File | File[] | Files that are not uploaded. |
Custom uploader event.
See uploader
Custom error event.
See error
name | type | description |
---|---|---|
xhr | XMLHttpRequest | XmlHttpRequest instance. |
files | File | File[] | Files that are not uploaded. |
Custom before send event.
See before-send
Custom remove event.
See remove
Defines the custom interfaces used by the module.
Custom passthrough(pt) option method.
name | type | default | description |
---|---|---|---|
instance | any | null | Defines instance. |
props | FileUploadProps | null | Defines valid properties. |
state | FileUploadState | null | Defines current inline state. |
attrs | any | null | Defines valid attributes. |
parent | any | null | Defines parent options. |
global | undefined | object | null | Defines passthrough(pt) options in global config. |
Custom remove upload file event.
Custom passthrough(pt) options.
name | type | default | description |
---|---|---|---|
root | FileUploadPassThroughOptionType | null | Used to pass attributes to the root's DOM element. |
input | FileUploadPassThroughOptionType | null | Used to pass attributes to the input's DOM element. |
buttonbar | FileUploadPassThroughOptionType | null | Used to pass attributes to the buttonbar's DOM element. |
chooseButton | FileUploadPassThroughOptionType | null | Used to pass attributes to the choose button's DOM element. |
chooseIcon | FileUploadPassThroughOptionType | null | Used to pass attributes to the choose icon's DOM element. |
chooseButtonLabel | FileUploadPassThroughOptionType | null | Used to pass attributes to the choose button label's DOM element. |
uploadButton | ButtonPassThroughOptions<FileUploadPassThroughMethodOptions | null | Used to pass attributes to the upload button's DOM element. |
cancelButton | ButtonPassThroughOptions<FileUploadPassThroughMethodOptions | null | Used to pass attributes to the cancel button's DOM element. |
content | FileUploadPassThroughOptionType | null | Used to pass attributes to the content's DOM element. |
progressbar | FileUploadPassThroughOptionType | null | Used to pass attributes to the progressbar's DOM element. |
message | MessagePassThroughOptions<FileUploadPassThroughMethodOptions | null | Used to pass attributes to the messages' DOM element. |
file | FileUploadPassThroughOptionType | null | Used to pass attributes to the file's DOM element. |
thumbnail | FileUploadPassThroughOptionType | null | Used to pass attributes to the thumbnail's DOM element. |
details | FileUploadPassThroughOptionType | null | Used to pass attributes to the details's DOM element. |
fileName | FileUploadPassThroughOptionType | null | Used to pass attributes to the fileName's DOM element. |
fileSize | FileUploadPassThroughOptionType | null | Used to pass attributes to the fileSize's DOM element. |
badge | BadgePassThroughOptions<FileUploadPassThroughMethodOptions | null | Used to pass attributes to the Badge component. |
actions | FileUploadPassThroughOptionType | null | Used to pass attributes to the actions's DOM element. |
removeButton | ButtonPassThroughOptions<FileUploadPassThroughMethodOptions | null | Used to pass attributes to the remove button's DOM element. |
empty | FileUploadPassThroughOptionType | null | Used to pass attributes to the empty's DOM element. |
label | FileUploadPassThroughOptionType | null | Used to pass attributes to the label's DOM element. |
uploadIcon | FileUploadPassThroughOptionType | null | Used to pass attributes to the upload icon's DOM element. |
hooks | ComponentHooks | null | Used to manage all lifecycle hooks. |
Custom passthrough attributes for each DOM elements
Defines current inline state in FileUpload component.
Defines the custom types used by the module.
values |
---|
FileUploadPassThroughAttributes | (options: FileUploadPassThroughMethodOptions) => undefined | string | null | undefined |