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.

View Demo

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.

app.component.html
app.component.ts
  • <dx-file-uploader ...
  • accept="image/*">
  • </dx-file-uploader>
  • import { DxFileUploaderModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxFileUploaderModule
  • ],
  • // ...
  • })

A user can upload only one file at a time. Set the multiple property to true to allow uploading several files at once.

app.component.html
app.component.ts
  • <dx-file-uploader ...
  • [multiple]="true">
  • </dx-file-uploader>
  • import { DxFileUploaderModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxFileUploaderModule
  • ],
  • // ...
  • })

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.

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.

app.component.ts
app.component.html
  • 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>

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