Angular FileManager File System Providers
File system providers are components that provide APIs used to access and modify virtual file systems. This section describes file system providers supported by the FileManager.
Custom
A custom file system provider allows you to implement custom APIs to access and use file systems.
Use the custom provider's methods to handle file operations (add, delete, rename, and so on).
The following code shows how to create a custom file system provider and bind the FileManager UI component to it:
- <dx-file-manager
- [fileSystemProvider]="fileSystemProvider">
- </dx-file-manager>
- import { Component } from '@angular/core';
- import CustomFileSystemProvider from 'devextreme/file_management/custom_provider';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- fileSystemProvider: CustomFileSystemProvider;
- constructor(http: HttpClient) {
- this.fileSystemProvider = new CustomFileSystemProvider({
- getItems,
- createDirectory,
- renameItem,
- deleteItem,
- // ...
- });
- }
- }
- function getItems(parentDirectory) {
- // ...
- }
- // other functions
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppComponent } from './app.component';
- import { DxFileManagerModule } from 'devextreme-angular';
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- DxFileManagerModule
- ],
- //...
- })
- export class AppModule { }
Object
The Object file system provider works with a file system represented by an in-memory array of JSON objects.
Assign the array to the data property. Data object fields should have conventional names listed in the data description. Otherwise, specify [fieldName]Expr properties: nameExpr, sizeExpr, dateModifiedExpr, and so on.
The following code shows how to bind the FileManager to the Object file system provider:
- <dx-file-manager id="fileManager"
- [fileSystemProvider]="fileItems">
- </dx-file-manager>
- import { Component } from '@angular/core';
- import ObjectFileSystemProvider from 'devextreme/file_management/object_provider';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- fileItems = [{
- name: "Documents",
- isDirectory: true,
- items: [{
- name: "Projects",
- isDirectory: true,
- items: [{
- name: "About.rtf",
- isDirectory: false,
- size: 1024
- }, {
- name: "Passwords.rtf",
- isDirectory: false,
- size: 2048
- }]
- },{
- name: "About.xml",
- isDirectory: false,
- size: 1024
- }]
- }];
- }
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppComponent } from './app.component';
- import { DxFileManagerModule } from 'devextreme-angular';
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- DxFileManagerModule
- ],
- //...
- })
- export class AppModule { }
Remote
The Remote file system provider works with a file system located on the server.
Set the endpointUrl property to specify the endpoint used to access and modify the file system.
The server should return data objects of the following structure:
- {
- name: "MyFile.jpg",
- size: 1024,
- dateModified: "2019/05/08",
- thumbnail: "/thumbnails/images/jpeg.ico",
- isDirectory: true,
- hasSubDirectories: true
- }
Fields in this structure have predefined names that FileManager uses in the default configuration. To use custom field names, configure [fieldName]Expr properties such as the following:
The following code snippet binds the FileManager to a RemoteFileSystemProvider:
- <dx-file-manager id="fileManager"
- [fileSystemProvider]="remoteFileProvider"
- ></dx-file-manager>
- import { Component } from '@angular/core';
- import { DxFileManagerModule } from 'devextreme-angular';
- import RemoteFileSystemProvider from 'devextreme/file_management/remote_provider';
- @Component({
- imports: [DxFileManagerModule], // ...
- })
- export class AppComponent {
- remoteFileProvider: RemoteFileSystemProvider;
- constructor() {
- this.remoteFileProvider = new RemoteFileSystemProvider({
- endpointUrl: "https://js.devexpress.com/Demos/Mvc/api/file-manager-file-system-scripts"
- });
- }
- }
On the server, process file management requests. DevExtreme includes request-processing helpers for ASP.NET MVC and ASP.NET Core. For an implementation example, enable the Backend API toggle in the following demo and review FileManagerScriptsApiController.cs:
You can also use remote file system providers with other DevExtreme components. The following example integrates RemoteFileSystemProvider with the DevExtreme TreeList: