JavaScript/jQuery FileUploader - Overview
The FileUploader UI component enables an end user to upload files to the server. An end user can select files in the file explorer or drag and drop files on the page's FileUploader area.
The following code adds the FileUploader to your page. Use the accept property to restrict the file types that can be uploaded to the server. This property is like the underlying <input>
element's "accept" attribute and accepts the same values described here.
jQuery
<div id="fileUploaderContainer"></div>
$(function() { $("#fileUploaderContainer").dxFileUploader({ // ... accept: "image/*" }); });
Angular
<dx-file-uploader ... accept="image/*"> </dx-file-uploader>
import { DxFileUploaderModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxFileUploaderModule ], // ... })
Vue
<template> <DxFileUploader accept="image/*" > </DxFileUploader> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxFileUploader } from 'devextreme-vue/file-uploader'; export default { components: { DxFileUploader }, data() { return { // ... }; } }; </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import FileUploader from 'devextreme-react/file-uploader'; class App extends React.Component { render() { return ( <FileUploader accept="image/*" > </FileUploader> ); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().FileUploader() .Accept("image/*") // ... )
ASP.NET Core Controls
@(Html.DevExtreme().FileUploader() .Accept("image/*") // ... )
A user is allowed to upload only one file at a time by default. Set the multiple property to true to allow uploading several files at once.
jQuery
$(function() { $("#fileUploaderContainer").dxFileUploader({ multiple: true }); });
Angular
<dx-file-uploader ... [multiple]="true"> </dx-file-uploader>
import { DxFileUploaderModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxFileUploaderModule ], // ... })
Vue
<template> <DxFileUploader :multiple="true" > </DxFileUploader> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxFileUploader } from 'devextreme-vue/file-uploader'; export default { components: { DxFileUploader }, data() { return { // ... }; } }; </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import FileUploader from 'devextreme-react/file-uploader'; class App extends React.Component { render() { return ( <FileUploader multiple={true} > </FileUploader> ); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().FileUploader() .Multiple(true) // ... )
ASP.NET Core Controls
@(Html.DevExtreme().FileUploader() .Multiple(true) // ... )
If you need to access the selected files at runtime, get the value of the value property using the following command. It returns an array, whose members are each an instance implementing the File interface.
var files = $("#fileUploaderContainer").dxFileUploader("option", "value");
With Angular, AngularJS, or Knockout, use a different technique. Bind the value property of the FileUploader UI component to a component property (in Angular), a scope property (in AngularJS), or an observable variable (in Knockout). After that, you can access the file array within any method.
Angular
import { DxFileUploaderModule } from "devextreme-angular"; // ... export class AppComponent { // ... value: any[] = []; getSelectedFiles () { return this.value; } } @NgModule({ imports: [ // ... DxFileUploaderModule ], // ... })
AngularJS
angular.module('DemoApp', ['dx']) .controller('DemoController', function DemoController($scope) { $scope.value = []; $scope.getSelectedFiles = function () { return $scope.value; } });
Knockout
var viewModel = { value: ko.observableArray(), getSelectedFiles: function () { return viewModel.value(); } };
ko.applyBindings(viewModel);
The FileUploader can operate in two different modes, each demanding a different client- and server-side configuration. See the Client-Side Settings article for more details.
See Also
- Configure a UI Component: Angular | Vue | React | jQuery | AngularJS | Knockout
- Upload Files - Server Side: ASP.NET | PHP
- File Validation
- FileUploader API Reference
If you have technical questions, please create a support ticket in the DevExpress Support Center.