-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add folder upload support to dcc.Upload component #3481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
95c27bb to
08f7541
Compare
- Add useFsAccessApi prop to enable folder selection - Support both click-to-select and drag-and-drop folder uploads - Recursively traverse folder structures using FileSystem API - Preserve folder hierarchy in uploaded filenames - Maintain backward compatibility (default: False) - Add integration tests for folder upload functionality Closes plotly#3464
08f7541 to
7a25fa9
Compare
|
@T4rk1n @KoolADE85 what do you think? |
|
Hey @LeticiaBN, thanks for submitting this PR! I think this a great feature to add to the component. I have a couple of thoughts on the approach:
|
…edback) - Remove useFsAccessApi prop in favor of automatic folder support with multiple=True - Implement accept prop filtering for folder uploads (extensions, MIME types, wildcards) - Add custom getDataTransferItems handler for drag-and-drop folder support - Add traverseFileTree method to recursively process folder contents - Preserve folder hierarchy in uploaded file names - Add webkitdirectory/directory/mozdirectory attributes when multiple=True - Improve integration tests following Dash testing best practices - Replace problematic test with focused, reliable tests This is now a drop-in improvement - existing apps using multiple=True automatically gain folder upload capability with no API changes required.
|
@KoolADE85 Hey! Thanks for the feedback! I've addressed all your points:
All tests pass locally. Let me know if you need any other changes! 🙂 |
🗂️ 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 whenmultiple=True, significantly reducing user effort when uploading multiple files from various directories.✨ Key Features
multiple=TruewebkitdirectoryHTML attributewebkitGetAsEntry())acceptprop - Filters uploaded files by type (extensions, MIME types, wildcards)folder/subfolder/file.txt)🌐 Browser Support
Browsers without support automatically fall back to file-only mode
📝 Example Usage
Basic Folder Upload
With File Type Filtering
🔧 Implementation Details
What Changed
React Components (
Upload.react.js):fileMatchesAccept()method to filter files based onacceptproptraverseFileTree()for recursive folder traversal with filteringgetDataTransferItems()handler for drag-and-drop folder supportwebkitdirectory,directory, andmozdirectoryattributes whenmultiple=TruePython Wrapper:
multipleprop documentation to mention folder upload capabilityTesting:
test_upfd001_folder_upload_with_multiple- verifies folder upload whenmultiple=Truetest_upfd002_folder_upload_disabled_with_single- verifies no folder upload whenmultiple=FalseTechnical Details
This implementation uses
webkitdirectory(HTML attribute) andwebkitGetAsEntry()(FileSystem API) for the following reasons:react-dropzonev4.1.2, which integrates seamlessly with these APIswebkitdirectoryand FileSystem API have been supported in Chrome/Edge since 2011acceptandmultiplepropsAddressing Reviewer Feedback
This PR addresses all reviewer feedback from the initial submission:
useFsAccessApiprop in favor of automatic folder support withmultiple=Trueacceptprop: Implemented full filtering for file extensions, MIME types, and wildcardsContributor Checklist
webkitdirectorywhenmultiple=Trueacceptprop filtering for folder contentsCHANGELOG.mdCloses #3464