string, default ""
e.g: image/*,.pdf
Equivalent to HTML5 file input accept attribute. Validated and error message is shown when selecting invalid files. Value can be a combination of: Unique file type specifiers
boolean, default true
Set it to false to disable smart background color (average color) for images and video thumbnails. Note: this prop is not reactive (not respected when changed at runtime)
string, default undefined
e.g: environment
user
Equivalent to HTML5 file input capture attribute.
Value can be either environment
or user
boolean, default false
Enables the compact mode which is useful for single file upload within a fixed size container. (See Profile Picture example below)
boolean, default false
Whether the file delete/cancel button should be showed.
boolean, default undefined
Disables all user interactions on the component
boolean, default false
Whether the file name can be edited. The (modified) name can be retrieved by fileRecord.name(withoutExtension = true)
. See also rename event.
object { type: 'Invalid file type', size: 'Files should not exceed <maxSize> in size' }
The error text messages to be displayed when accept
or maxSize
validation fails.
string Choose files or drag & drop here
The text to be shown at the file input.
boolean, default false
Whether the file icon is linkable (clickable/downloadable). Only available for preloaded files with urls.
number, default none
e.g: 12
Limits the maximum files allowed to be selected. Ignores the extra files.
string, default none
e.g: 2.5MB
Validates each file and shows error message for invalid files.
boolean, default true
Whether the file meta (file name, size, etc) showed.
boolean, default auto
Whether the file input allows multiple files. Default value is determined by the type of v-model
- if an array is provided, multiple mode is enabled. Note that, when multiple is false, dragging and dropping a file results in replacing the existing file.
boolean, default false
Enable resumable upload with tus.io protocol. You need to install tus-js-client for this to work. And you have to pass the tus
object to plugins.tus
as in the following example.
with npm:
// npm install tus-js-client --save
import tus from 'tus-js-client';
import { plugins } from 'vue-file-agent';
plugins.tus = tus;
with script tag:
<script src="https://unpkg.com/tus-js-client@latest/dist/tus.js"></script>
<script src="https://unpkg.com/vue-file-agent@latest/dist/vue-file-agent.umd.js"></script>
<script>
if (window.tus && window.VueFileAgent) {
window.VueFileAgent.plugins.tus = tus;
}
</script>
boolean or string (true
- drag to sort, 'hold'
- hold and drag to sort, 'handle'
- drag the handle to sort), default false
Whether the files can be drag sorted. You need to install vue-slicksort for this to work. And you have to define two components vfa-sortable-list
and vfa-sortable-item
.
with npm:
// npm install vue-slicksort --save
import { SlickList, SlickItem } from 'vue-slicksort';
Vue.component('vfa-sortable-list', SlickList);
Vue.component('vfa-sortable-item', SlickItem);
with script tag:
<script src="https://unpkg.com/vue-slicksort@latest/dist/vue-slicksort.min.js"></script>
<script>
if (window.VueSlicksort) {
Vue.component('vfa-sortable-list', window.VueSlicksort.SlickList);
Vue.component('vfa-sortable-item', window.VueSlicksort.SlickItem);
}
</script>
string, default none
When provided, a theme class is added to the container .theme-<theme>
.
Officially supported themes: default
(grid view), list
(list view)
number, default 360
Image and Video file preview thumbnails are resized to this size. Bigger numbers resut in better quality thumbnails, smaller numbers result in faster preview generation.
function default none
Configure the XMLHttpRequest
instance to be sent to server
e.g
<template>
<VueFileAgent
:uploadConfig="
(xhr) => {
xhr.timeout = 25000;
}
"
>
</VueFileAgent>
</template>
object default none
Headers to pass to uploadUrl
string default none
When this prop is provided, built in uploader is triggerred as soon as files are selected. And when delete button is clicked, built in uploader’s delete function is called.
boolean default undefined
Set XMLHttpRequest.withCredentials
See v-model
below
Accepts an object for single file upload and an array of serialized FileRecord objects for multiple file upload.
Demo 1. Preloading Existing Files (CodePen)
Code Edit CodePen
Result Edit CodePen
$event
: FileRecord instance
$event
: array of serialized FileRecord
Fired whenever files are selected. Passes all selected files data (including previously selected). You shouldn’t use this event directly. Instead, use v-model for two way binding, and use select
event for other purposes
$event
: FileRecord instance
Fired when the remove icon (x
) is pressed. You may have to call deleteFileRecord
method (See methods) when beforedelete
event is triggered. In auto upload mode deleteFileRecord
is called implicitly.
E.g
<template>
<VueFileAgent
ref="fileAgent"
@beforedelete="onBeforeDelete($event)"
@delete="onDelete($event)"
</VueFileAgent>
</template>
<script>
export default {
// ...
metods: {
// ...
onBeforeDelete(fileRecord){
if(confirm('Are you sure?')){
this.$refs.fileAgent.deleteFileRecord(fileRecord);
}
},
onDelete(fileRecord){
this.$refs.fileAgent.deleteUpload(/* ... */);
}
// ...
}
// ...
}
</script>
$event
: FileRecord instance
Fired as soon as file is renamed. See also editable prop.
$event
: array of serialized FileRecord
Fired whenever files are selected. Passes the (newly selected) files data.
$event
: array of upload ajax response/error for each file
Fired after files are uploaded. If any file fails to be uploaded, representing response.error
becomes truthy. If all files fail to be uploaded, upload:error
is trigged instead.
<template>
<VueFileAgent
@upload="onUpload($event)"
@upload:error="onUploadError($event)"
</VueFileAgent>
</template>
<script>
export default {
// ...
methods: {
// ...
onUpload(responses) {
for (response of responses) {
if (response.error) {
// handle error
continue;
}
// handle success
}
},
onUploadError(failedResponses) {
// handle error
}
// ...
}
// ...
}
</script>
$event
: upload update response
Fired after file is updated (renamed). If the file fails to be uploaded, upload:update:error
is triggered instead.
$event
: upload delete response
Fired after file is deleted. If the file fails to be deleted, upload:delete:error
is triggered instead.
fileRecord
: FileRecord | RawFileRecord): voidfileRecord
from the list and triggers delete
eventuploadUrl
: string, uploadHeaders
: object, fileRecords
: FileRecord[] | RawFileRecord[], createFormData
?: (fileRecord: FileRecord) => FormData, uploadConfig
?: (request: XMLHttpRequest) => any): PromiseuploadUrl
: the url where a POST
request will be sentuploadHeaders
: a key value pair of custom headers. e.g: {'Authorization': 'MyCustomAuthorizationHeader'}
fileRecords
: array of files data to uploadcreateFormData
: [Optional] create a custom FormData instance for upload See ExampleuploadConfig
: [Optional] configure the XMLHttpRequest
object to be sent to serverTrigger the default upload action.
uploadUrl
: string, uploadHeaders
: object, fileRecord
: FileRecord | RawFileRecord, uploadData
?: any, uploadConfig
?: (request: XMLHttpRequest) => any): PromiseuploadUrl
: the url where a DELETE
request will be sentuploadHeaders
: an key value pair of custom headers. e.g: {'Authorization': 'MyCustomAuthorizationHeader'}
fileRecord
: file record to be deleteduploadData
: [Optional] the data returned in upload
operationuploadConfig
: [Optional] configure the XMLHttpRequest
object to be sent to serverTrigger the default delete upload action.
Content is placed (before) inside of the file input.
Content is placed (after) outside of the file input. Files can be dragged here. When files are over dragged over this area is-drag-over
class is added to the parent.
Content is placed (before) inside of the file input.
Content is placed (before) outside of the file input. Files can be dragged here. When files are over dragged over this area is-drag-over
class is added to the parent.
Preview block of each FileRecord. fileRecord
and index
slot properties are available
Content before preview block of each FileRecord. fileRecord
and index
slot properties are available
Content after preview block of each FileRecord. fileRecord
and index
slot properties are available
Upload help text (“Choose files…”) and icon
Can be used to customize sortable handle icon
Demo 2. Profile Picture (CodePen)
Code Edit CodePen
Result Edit CodePen
If you still can’t make it with the built in customizations, (1) you can create a theme and pass it via theme prop, or (2) you can import the provided mixin and define a custom template. e.g:
<!-- my-vue-file-agent.vue (component) -->
<template>
<div class="my-vue-file-agent">
<ul>
<li v-for="fileRecord in fileRecords">
{{ fileRecord.name() }}
</li>
</ul>
<button @click="myCustomMethod()">Custom Button</button>
</div>
</template>
<script>
import { mixin } from 'vue-file-agent';
export default {
mixins: [mixin],
methods: {
myCustomMethod() {
// bla bla
},
},
};
</script>
Demo 3. Gmail Inspired Upload (CodePen)
NOTE
In an ES6 environment, instead of using <template v-slot:file-preview="slotProps">
you can use <template v-slot:file-preview="{ fileRecord, index }">
Code Edit CodePen
Result Edit CodePen