# file-manager-directory-upload

> File manager with a toolbar dropdown to upload either individual files or a whole folder.

**Framework:** react  **Component:** FileManager  **Variant:** directory-upload

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/react/js/file-manager-directory-upload.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-filemanager @syncfusion/ej2-react-splitbuttons
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/file-manager-directory-upload/FileManager.jsx

```jsx
import { useRef, useState } from 'react';
import { FileManagerComponent, Inject, NavigationPane, DetailsView, Toolbar, ToolbarItemsDirective, ToolbarItemDirective } from '@syncfusion/ej2-react-filemanager';
import { DropDownButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
/**
 * File Manager folder upload sample
 */
const DirectoryUpload = () => {
    const [isDirectoryUpload, setIsDirectoryUpload] = useState(false);
    let fmObj = useRef(null);
    const dropBtnRef = useRef(null);
    let hostUrl = "https://physical-service.syncfusion.com/";
    const OnCreated = () => {
        if (fmObj.current && dropBtnRef.current) {
            const fm = fmObj.current;
            const uploadText = fm.localeObj.getConstant('Upload');
            dropBtnRef.current.content = `<span class="e-tbar-btn-text">${uploadText}</span>`;
            dropBtnRef.current.items = [
                { text: fm?.localeObj?.getConstant('Folder') || 'Folder' },
                { text: fm?.localeObj?.getConstant('File') || 'File' },
            ];
        }
    };
    const onSelect = (args) => {
        if (args.item.text === fmObj.current?.localeObj.getConstant('Folder')) {
            setIsDirectoryUpload(true);
        }
        else {
            setIsDirectoryUpload(false);
        }
        setTimeout(() => {
            let uploadBtn = document.querySelector('.e-file-select-wrap button');
            uploadBtn.click();
        }, 100);
    };
    const uploadClick = (e) => {
        e.stopPropagation();
    };
    const uploadTemplate = () => {
        return (<DropDownButtonComponent ref={dropBtnRef} id="dropButton" cssClass="e-tbar-btn e-tbtn-txt" onClick={uploadClick} iconCss='e-icons e-fe-upload' select={onSelect} created={OnCreated}>
            </DropDownButtonComponent>);
    };
    return (<div>
            <div className="control-section">
                <FileManagerComponent id="file" ref={fmObj} uploadSettings={{ directoryUpload: isDirectoryUpload }} ajaxSettings={{ url: hostUrl + "api/FileManager/FileOperations", getImageUrl: hostUrl + "api/FileManager/GetImage", uploadUrl: hostUrl + 'api/FileManager/Upload', downloadUrl: hostUrl + 'api/FileManager/Download' }} contextMenuSettings={{
            file: ['Cut', 'Copy', '|', 'Delete', 'Download', 'Rename', '|', 'Details'],
            visible: true
        }}>
                    <ToolbarItemsDirective>
                            <ToolbarItemDirective name='NewFolder'/>
                            <ToolbarItemDirective template={uploadTemplate} name="Upload"/>
                            <ToolbarItemDirective name="SortBy"/>
                            <ToolbarItemDirective name="Refresh"/>
                            <ToolbarItemDirective name="Cut"/>
                            <ToolbarItemDirective name="Copy"/>
                            <ToolbarItemDirective name="Paste"/>
                            <ToolbarItemDirective name="Delete"/>
                            <ToolbarItemDirective name="Download"/>
                            <ToolbarItemDirective name="Rename"/>
                            <ToolbarItemDirective name="Selection"/>
                            <ToolbarItemDirective name="View"/>
                            <ToolbarItemDirective name="Details"/>
                        </ToolbarItemsDirective>
                    <Inject services={[NavigationPane, DetailsView, Toolbar]}/>
                </FileManagerComponent>
            </div>
        </div>);
};
export default DirectoryUpload;

```
