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
averageColor
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)
capture
string, default undefined
e.g: environmentuser
Equivalent to HTML5 file input capture attribute.
Value can be either environment or user
compact
boolean, default false
Enables the compact mode which is useful for single file upload within a fixed size container. (See Profile Picture example below)
deletable
boolean, default false
Whether the file delete/cancel button should be showed.
disabled
boolean, default undefined
Disables all user interactions on the component
editable
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.
errorText
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.
helpText
string Choose files or drag & drop here
The text to be shown at the file input.
linkable
boolean, default false
Whether the file icon is linkable (clickable/downloadable). Only available for preloaded files with urls.
maxFiles
number, default none
e.g: 12
Limits the maximum files allowed to be selected. Ignores the extra files.
maxSize
string, default none
e.g: 2.5MB
Validates each file and shows error message for invalid files.
meta
boolean, default true
Whether the file meta (file name, size, etc) showed.
multiple
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.
resumable
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.
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.
When provided, a theme class is added to the container .theme-<theme>.
Officially supported themes: default (grid view), list (list view)
thumbnailSize
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.
uploadConfig
function default none
Configure the XMLHttpRequest instance to be sent to server
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.
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
beforedelete
$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><VueFileAgentref="fileAgent"@beforedelete="onBeforeDelete($event)"@delete="onDelete($event)"</VueFileAgent></template><script>exportdefault{// ...metods:{// ...onBeforeDelete(fileRecord){if(confirm('Are you sure?')){this.$refs.fileAgent.deleteFileRecord(fileRecord);}},onDelete(fileRecord){this.$refs.fileAgent.deleteUpload(/* ... */);}// ...}// ...}</script>
rename
$event: FileRecord instance
Fired as soon as file is renamed. See also editable prop.
select
$event: array of serialized FileRecord
Fired whenever files are selected. Passes the (newly selected) files data.
upload, upload:error
$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.
uploadUrl: the url where a DELETE request will be sent
uploadHeaders: an key value pair of custom headers. e.g: {'Authorization': 'MyCustomAuthorizationHeader'}
fileRecord: file record to be deleted
uploadData: [Optional] the data returned in upload operation
uploadConfig: [Optional] configure the XMLHttpRequest object to be sent to server
Trigger the default delete upload action.
Slots
after-inner
Content is placed (before) inside of the file input.
after-outer
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.
before-inner
Content is placed (before) inside of the file input.
before-outer
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.
file-preview
Preview block of each FileRecord. fileRecord and index slot properties are available
file-preview-before
Content before preview block of each FileRecord. fileRecord and index slot properties are available
file-preview-after
Content after preview block of each FileRecord. fileRecord and index slot properties are available
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><divclass="my-vue-file-agent"><ul><liv-for="fileRecord in fileRecords">{{fileRecord.name()}}</li></ul><button@click="myCustomMethod()">Custom Button</button></div></template><script>import{mixin}from'vue-file-agent';exportdefault{mixins:[mixin],methods:{myCustomMethod(){// bla bla},},};</script>
NOTE In an ES6 environment, instead of using <template v-slot:file-preview="slotProps"> you can use <template v-slot:file-preview="{ fileRecord, index }">
<template><divclass="vfa-demo bg-light pt-3"><VueFileAgentclass="upload-block"ref="vfaDemoRef":uploadUrl="'https://www.mocky.io/v2/5d4fb20b3000005c111099e3'":uploadHeaders="{}":multiple="true":deletable="true":theme="'list'":maxSize="'25MB'":errorText="{
size: 'This file is too large to be attached',
}"v-model="fileRecords"><templatev-slot:before-outer><p>Email Attachment example with drag & drop support and <spanclass="badge">attachment</span> keyword basic detection.</p><divclass="form-group"><inputtype="text"class="form-control"placeholder="Your Name"value="John Doe"></div><divclass="form-group"><inputtype="email"class="form-control"placeholder="Email address"value="johndoe@example.com"></div><divclass="form-group"><textareav-model="message"class="form-control"placeholder="Your Message"></textarea></div></template><templatev-slot:file-preview="slotProps"><div:key="slotProps.index"class="grid-box-item file-row"><buttontype="button"class="close remove"aria-label="Remove"@click="removeFileRecord(slotProps.fileRecord)"><spanaria-hidden="true">×</span></button><divclass="progress":class="{'completed': slotProps.fileRecord.progress() == 100}"><divclass="progress-bar"role="progressbar":style="{width: slotProps.fileRecord.progress() + '%'}"></div></div><strong>{{ slotProps.fileRecord.name() }}</strong><spanclass="text-muted">({{ slotProps.fileRecord.size() }})</span></div></template><templatev-slot:file-preview-new><divclass="text-left my-3"key="new"><ahref="#"class="">Select files</a> or drag & drop here
</div></template><!-- <template v-slot:after-inner>
<div class="text-left pt-1">
<a href="#" class="">Select files</a> or drag & drop here
</div>
</template > --><templatev-slot:after-outer><divtitle="after-outer"><divclass="drop-help-text"><p>Drop here</p></div><buttontype="button"class="btn btn-primary"@click="send()">Send</button></div></template></VueFileAgent></div></template><script>exportdefault{data:function(){return{fileRecords:[],message:'I am sending you the attachments',}},methods:{removeFileRecord:function(fileRecord){returnthis.$refs.vfaDemoRef.removeFileRecord(fileRecord);},send:function(){if(this.message.indexOf('attachment')!==-1&&this.fileRecords.length<1){if(!confirm('You have mentioned about attachments in your message. Are you sure to send without attachments?')){return;}}alert('Message sent!');}}}</script><style>.vfa-demo{position:relative;}.vfa-demo.file-preview-wrapper::before{background:transparent;}.vfa-demo.file-row{position:relative;z-index:15;line-height:24px;text-align:left;background:#EEE;margin-bottom:5px;padding:2px5px;}.vfa-demo.remove{float:right;margin-top:-3px;}.vfa-demo.progress{float:right;width:85px;height:10px;margin-top:7px;margin-right:10px;background:#FFF;border:1pxsolid#AAA;}.vfa-demo.progress.completed{display:none;}.vfa-demo.drop-help-text{position:absolute;top:0;right:0;bottom:0;left:0;margin:2px;background:rgba(255,255,255,0.75);z-index:1200;font-size:32px;font-weight:bold;color:#888;align-items:center;justify-content:center;display:none;}.vfa-demo.is-drag-over.drop-help-text{display:flex;}.vfa-demo.upload-block{border:2pxdashedtransparent;padding:20px;padding-top:0;}.vfa-demo.is-drag-over.upload-block{border-color:#AAA;}.vfa-demo.vue-file-agent{border:0!important;box-shadow:none!important;}</style>