DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Vue File Uploader - Async Upload

In this demo, the FileUploader component is configured for asynchronous upload. Use the File types drop-down menu to select acceptable file types for the Open file dialog. The Upload mode drop-down menu allows you to specify whether the file is uploaded on a button click or instantly after the file has been selected. In addition, you can specify whether the FileUploader allows multiple file selection.

Backend API
<template> <div> <div class="widget-container"> <DxFileUploader :accept="accept" :multiple="multiple" :upload-mode="uploadMode" upload-url="https://js.devexpress.com/Demos/NetCore/FileUploader/Upload" @value-changed="onValueChanged" /> <div :style="{display: files.length > 0 ? 'block' : 'none'}" class="content" > <div> <h4>Selected Files</h4> <div v-for="(file, index) in files" :key="index" class="selected-item" > <span>Name: {{ file.name }}<br></span> <span>Size {{ file.size }}<br></span> <span>Type {{ file.type }}<br></span> <span>Last Modified Date: {{ file.lastModified }}</span> </div> </div> </div> </div> <div class="options-panel"> <div class="caption">Options</div> <div class="option"> <span>File types</span> <DxSelectBox :data-source="fileTypesSource" value-expr="value" :input-attr="{ 'aria-label': 'File Type' }" display-expr="name" value="*" @value-changed="onFileTypeChanged" /> </div> <div class="option"> <span>Upload mode</span> <DxSelectBox :items="['instantly', 'useButtons']" value="instantly" :input-attr="{ 'aria-label': 'Mode' }" @value-changed="onUploadModeChanged" /> </div> <div class="option"> <DxCheckBox text="Allow multiple files selection" @value-changed="onMultipleChanged" /> </div> </div> </div> </template> <script setup lang="ts"> import { ref } from 'vue'; import { DxFileUploader, type DxFileUploaderTypes } from 'devextreme-vue/file-uploader'; import { DxCheckBox, type DxCheckBoxTypes } from 'devextreme-vue/check-box'; import { DxSelectBox, type DxSelectBoxTypes } from 'devextreme-vue/select-box'; const multiple = ref(false); const accept = ref('*'); const uploadMode = ref<DxFileUploaderTypes.FileUploadMode>('instantly'); const fileTypesSource = [ { name: 'All types', value: '*' }, { name: 'Images', value: 'image/*' }, { name: 'Videos', value: 'video/*' }, ]; const files = ref<File[]>([]); function onValueChanged(e: DxFileUploaderTypes.ValueChangedEvent) { files.value = e.value || []; } function onFileTypeChanged(e: DxSelectBoxTypes.ValueChangedEvent) { accept.value = e.value; } function onUploadModeChanged(e: DxSelectBoxTypes.ValueChangedEvent) { uploadMode.value = e.value; } function onMultipleChanged(e: DxCheckBoxTypes.ValueChangedEvent) { multiple.value = e.value; } </script> <style> .widget-container { margin-right: 320px; } .content h4 { margin-bottom: 10px; font-weight: 500; font-size: 18px; } .content { margin-top: 50px; margin-left: 10px; display: none; } .selected-item { margin-bottom: 20px; } .options-panel { padding: 20px; background-color: rgba(191, 191, 191, 0.15); position: absolute; right: 0; top: 0; bottom: 0; width: 260px; } .caption { font-size: 18px; font-weight: 500; } .option { margin-top: 10px; } </style>
import { createApp } from 'vue'; import App from './App.vue'; import 'anti-forgery'; createApp(App).mount('#app');
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="./bundle.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"> </div> </div> <script src="bundles/vendor/vue.vendor.js"></script> <script src="./bundle.js"></script> </body> </html>

To select files, click the Select file button or drop the files directly on the component. If the upload mode is «useButtons», you must click the Upload button or a corresponding button for each file to initiate upload.

This demo does not actually upload files. To upload files, assign the URL of a page providing server scenarios for saving uploaded files to the uploadUrl configuration property of the component.