Angular 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'; function App() { return ( <FileUploader accept="image/*" > </FileUploader> ); } export default App;
A user can upload only one file at a time. 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'; function App() { return ( <FileUploader multiple={true} > </FileUploader> ); } export default App;
If you need to access the selected files at runtime, get the value of the value property. The following command returns an array, whose members are each an instance implementing the File interface.
jQuery
const files = $("#fileUploaderContainer").dxFileUploader("option", "value");
With Angular, Vue, or React, use a different technique. Bind the value property of the FileUploader UI component to a component property. 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 ], // ... })
<dx-file-uploader ... [(value)]="value"> </dx-file-uploader>
Vue
<template> <DxFileUploader ... @value-changed="e => value = e.value" /> </div> </template> <script> import { DxFileUploader } from 'devextreme-vue/file-uploader'; export default { components: { DxFileUploader, }, data() { return { value: [] }; }, methods: { getSelectedFiles () { return this.value; } }, }; </script>
React
import React, {useState} from 'react'; import FileUploader from 'devextreme-react/file-uploader'; function App() { const [value, setValue] = useState([]); const changeValue = (e) => { setValue(e.value); } const getSelectedFiles = () => { return value; } return ( <FileUploader ... value={value} onValueChanged={changeValue} /> ); } export default App;
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
jQuery
Angular
Vue
React
- 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.