feat: Add folder upload support to dcc.Upload component #3481
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🗂️ Add Folder Upload Support to dcc.Upload Component
This PR adds folder upload capability to the
dcc.Uploadcomponent, addressing issue #3464. Users can now select and upload entire folders (including nested subfolders) via both click-to-select and drag-and-drop methods, significantly reducing user effort when uploading multiple files from various directories.✨ Key Features
useFsAccessApiprop enables folder selection in addition to fileswebkitdirectoryHTML attributewebkitGetAsEntry())folder/subfolder/file.txt)useFsAccessApi=False)🌐 Browser Support
Browsers without support automatically fall back to file-only mode
📝 Example Usage
🔧 Implementation Details
React Components:
useFsAccessApiPropType with documentationtraverseFileTree()for recursive folder traversalgetDataTransferItems()handler for drag-and-dropwebkitdirectoryattribute for file pickerPython Wrapper:
useFsAccessApiparameter todcc.UploadTesting:
multiplepropTechnical Note:
This implementation uses
webkitdirectory(HTML attribute) andwebkitGetAsEntry()(FileSystem API) instead of the newer File System Access API for the following reasons:Compatibility with react-dropzone v4.1.2: The current Dash codebase uses
react-dropzonev4.1.2, which predates the File System Access API and doesn't have built-in support for it.Future upgrade path: If Dash upgrades to a newer version of react-dropzone (v14+), migrating to the full File System Access API would be straightforward, as the prop name (
useFsAccessApi) already hints at this capability.Contributor Checklist
useFsAccessApiprop to React componentwebkitdirectoryOptionals
CHANGELOG.mdCloses #3464