Your search did not match any results.
File Uploader

File Uploading

Documentation

In this demo, the FileUploader widget 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 widget allows multiple file selection.

To select files, click the Select file button or drop the files directly on the widget. 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 option of the widget.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import { FileUploader, SelectBox, CheckBox } from 'devextreme-react'; 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/Content/Services/upload.aspx'} 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={['instantly', 'useButtons']} 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/19.1.6/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.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; }
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@16/umd/react.development.js', 'react-dom': 'npm:react-dom@16/umd/react-dom.development.js', 'prop-types': 'npm:prop-types/prop-types.js', 'devextreme': 'npm:devextreme@19.1', 'devextreme-react': 'npm:devextreme-react@19.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.6/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' } }, babelOptions: { sourceMaps: false, stage0: true, react: true } });