React 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
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:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import FileManager from 'devextreme-react/file-manager';
- import CustomFileSystemProvider from 'devextreme/file_management/custom_provider';
- class App extends React.Component {
- render() {
- constructor() {
- super();
- this.fileSystemProvider = new CustomFileSystemProvider({
- getItems,
- createDirectory,
- renameItem,
- deleteItem,
- // ...
- });
- }
- return (
- <FileManager
- fileSystemProvider={fileSystemProvider}>
- </FileManager>
- );
- }
- }
- function getItems(parentDirectory) {
- // ...
- }
- // other functions
- export default App;
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:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import FileManager from 'devextreme-react/file-manager';
- import ObjectFileSystemProvider from 'devextreme/file_management/object_provider';
- class App extends React.Component {
- render() {
- return (
- <FileManager fileSystemProvider={fileItems}>
- </FileManager>
- );
- }
- }
- export default App;
- export const 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
- }]
- }];
Remote
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 conventional names that you can change via [fieldName]Expr properties: nameExpr, sizeExpr, dateModifiedExpr, and so on.
The following code shows how to bind the FileManager to the Remote file system provider:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import FileManager from 'devextreme-react/file-manager';
- import RemoteFileSystemProvider from 'devextreme/file_management/remote_provider';
- const remoteFileProvider = new RemoteFileSystemProvider({
- endpointUrl: 'https://js.devexpress.com/Demos/Mvc/api/file-manager-file-system-scripts'
- });
- class App extends React.Component {
- render() {
- return (
- <FileManager
- fileSystemProvider={remoteFileProvider}>
- {/* ... */}
- </FileManager>
- );
- }
- }
- export default App;
On the server-side, you need to process file management requests. DevExtreme provides helpers for ASP.NET MVC and ASP.NET Core that do this. To view the server-side code, navigate to the FileManagerApiController.cs
tab in the following demo:
If you have technical questions, please create a support ticket in the DevExpress Support Center.