DevExtreme v23.2 is now available.

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

Your search did not match any results.

Async Upload

Documentation

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.

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.

NOTE

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.

Backend API
$(() => { const fileUploader = $('#file-uploader').dxFileUploader({ multiple: false, accept: '*', value: [], uploadMode: 'instantly', uploadUrl: 'https://js.devexpress.com/Demos/NetCore/FileUploader/Upload', onValueChanged(e) { const files = e.value; if (files.length > 0) { $('#selected-files .selected-item').remove(); $.each(files, (i, file) => { const $selectedItem = $('<div />').addClass('selected-item'); $selectedItem.append( $('<span />').html(`Name: ${file.name}<br/>`), $('<span />').html(`Size ${file.size} bytes<br/>`), $('<span />').html(`Type ${file.type}<br/>`), $('<span />').html(`Last Modified Date: ${file.lastModifiedDate}`), ); $selectedItem.appendTo($('#selected-files')); }); $('#selected-files').show(); } else { $('#selected-files').hide(); } }, }).dxFileUploader('instance'); $('#accept-option').dxSelectBox({ inputAttr: { 'aria-label': 'Accept Option' }, dataSource: [ { name: 'All types', value: '*' }, { name: 'Images', value: 'image/*' }, { name: 'Videos', value: 'video/*' }, ], valueExpr: 'value', displayExpr: 'name', value: '*', onValueChanged(e) { fileUploader.option('accept', e.value); }, }); $('#upload-option').dxSelectBox({ items: ['instantly', 'useButtons'], value: 'instantly', inputAttr: { 'aria-label': 'Upload Option' }, onValueChanged(e) { fileUploader.option('uploadMode', e.value); }, }); $('#multiple-option').dxCheckBox({ value: false, text: 'Allow multiple files selection', onValueChanged(e) { fileUploader.option('multiple', e.value); }, }); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <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=1.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/23.2.5/css/dx.light.css" /> <script src="js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="fileuploader"> <div class="widget-container"> <div id="file-uploader"></div> <div class="content" id="selected-files"> <div> <h4>Selected Files</h4> </div> </div> </div> <div class="options"> <div class="caption">Options</div> <div class="option"> <span>File types</span> <div id="accept-option"></div> </div> <div class="option"> <span>Upload mode</span> <div id="upload-option"></div> </div> <div class="option"> <div id="multiple-option"></div> </div> </div> </div> </div> </body> </html>
.widget-container { margin-right: 320px; } .content h4 { margin-bottom: 10px; font-weight: 500; font-size: 18px; } .content { margin-top: 50px; margin-left: 10px; } .selected-item { margin-bottom: 20px; } #selected-files { display: none; } .options { 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; }