Your search did not match any results.
File Uploader

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
Copy to CodeSandBox
Apply
Reset
import React from 'react'; import FileUploader from 'devextreme-react/file-uploader'; import SelectBox from 'devextreme-react/select-box'; import CheckBox from 'devextreme-react/check-box'; const uploadModes = ['instantly', 'useButtons']; class App extends React.Component { constructor(props) { super(props); this.state = { multiple: false, uploadMode: 'instantly', accept: '*', selectedFiles: [] }; this.fileTypesSource = [ { name: 'All types', value: '*' }, { name: 'Images', value: 'image/*' }, { name: 'Videos', value: 'video/*' } ]; this.onSelectedFilesChanged = this.onSelectedFilesChanged.bind(this); this.onAcceptChanged = this.onAcceptChanged.bind(this); this.onUploadModeChanged = this.onUploadModeChanged.bind(this); this.onMultipleChanged = this.onMultipleChanged.bind(this); } render() { return ( <div> <div className="widget-container"> <FileUploader multiple={this.state.multiple} accept={this.state.accept} uploadMode={this.state.uploadMode} uploadUrl="https://js.devexpress.com/Demos/NetCore/FileUploader/Upload" onValueChanged={this.onSelectedFilesChanged} /> <div className="content" style={{ display: this.state.selectedFiles.length > 0 ? 'block' : 'none' }}> <div> <h4>Selected Files</h4> { this.state.selectedFiles.map((file, i) => { return <div className="selected-item" key={i}> <span>{`Name: ${file.name}`}<br /></span> <span>{`Size ${file.size}`}<br /></span> <span>{`Type ${file.size}`}<br /></span> <span>{`Last Modified Date: ${file.lastModifiedDate}`}</span> </div>; }) } </div> </div> </div> <div className="options"> <div className="caption">Options</div> <div className="option"> <span>File types</span> <SelectBox dataSource={this.fileTypesSource} valueExpr="value" displayExpr="name" defaultValue="*" onValueChanged={this.onAcceptChanged} /> </div> <div className="option"> <span>Upload mode</span> <SelectBox items={uploadModes} defaultValue="instantly" onValueChanged={this.onUploadModeChanged} /> </div> <div className="option"> <CheckBox text="Allow multiple files selection" onValueChanged={this.onMultipleChanged} /> </div> </div> </div> ); } onSelectedFilesChanged(e) { this.setState({ selectedFiles: e.value }); } onAcceptChanged(e) { this.setState({ accept: e.value }); } onUploadModeChanged(e) { this.setState({ uploadMode: e.value }); } onMultipleChanged(e) { this.setState({ multiple: e.value }); } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app') );
<!DOCTYPE html> <html> <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" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.1.6/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.1.6/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></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; display: none; } .selected-item { margin-bottom: 20px; } .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; }
window.config = { transpiler: 'plugin-babel', meta: { 'devextreme/localization.js': { "esModule": true }, }, paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@17.0.2/umd/react.development.js', 'react-dom': 'npm:react-dom@17.0.2/umd/react-dom.development.js', 'prop-types': 'npm:prop-types@15.7.2/prop-types.js', 'rrule': 'npm:rrule@2.6.6/dist/es5/rrule.js', 'luxon': 'npm:luxon@1.28.0/build/global/luxon.min.js', 'es6-object-assign': 'npm:es6-object-assign@1.1.0', 'devextreme': 'npm:devextreme@21.1.6/cjs', 'devextreme-react': 'npm:devextreme-react@21.1.6', 'jszip': 'npm:jszip@3.7.1/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@1.4.2/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.1.32/dist/dx-diagram.js', 'devexpress-gantt': 'npm:devexpress-gantt@3.0.14/dist/dx-gantt.js', '@devextreme/vdom': 'npm:@devextreme/vdom@1.2.2', 'inferno': 'npm:inferno@7.4.10/dist/inferno.min.js', 'inferno-compat': 'npm:inferno-compat@7.4.10/dist/inferno-compat.min.js', 'inferno-create-element': 'npm:inferno-create-element@7.4.10/dist/inferno-create-element.min.js', 'inferno-dom': 'npm:inferno-dom@1.0.7/dist/inferno-dom.min.js', 'inferno-hydrate': 'npm:inferno-hydrate@7.4.10/dist/inferno-hydrate.min.js', 'inferno-clone-vnode': 'npm:inferno-clone-vnode@7.4.10/dist/inferno-clone-vnode.min.js', 'inferno-create-class': 'npm:inferno-create-class@7.4.10/dist/inferno-create-class.min.js', 'inferno-extras': 'npm:inferno-extras@7.4.10/dist/inferno-extras.min.js', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0.0.25/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js' }, packages: { 'devextreme': { defaultExtension: 'js' }, '@devextreme/vdom': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' }, 'devextreme/events/utils': { main: 'index' }, 'devextreme/events': { main: 'index' }, 'es6-object-assign': { main: './index.js', defaultExtension: 'js' } }, packageConfigPaths: [ "npm:@devextreme/*/package.json", ], babelOptions: { sourceMaps: false, stage0: true, react: true } }; System.config(window.config);