feat(file-picker): add with_data support for web file content#6199
Open
FeodorFitsner wants to merge 2 commits intomainfrom
Open
feat(file-picker): add with_data support for web file content#6199FeodorFitsner wants to merge 2 commits intomainfrom
FeodorFitsner wants to merge 2 commits intomainfrom
Conversation
Add support for returning file contents (bytes) from FilePicker via a new with_data flag. Dart changes: introduce withData handling, include bytes in FilePickerFile map, and toggle withReadStream accordingly. Python SDK: add bytes field and docstring to FilePickerFile, expose with_data parameter in pick_files payload, normalize incoming byte arrays to bytes, and update returned objects. Also add an example script (pick_and_save_text_content.py) demonstrating picking and saving text content.
ndonkoHenri
reviewed
Feb 22, 2026
ndonkoHenri
reviewed
Feb 22, 2026
ndonkoHenri
reviewed
Feb 22, 2026
sdk/python/examples/services/file_picker/pick_and_save_text_content.py
Outdated
Show resolved
Hide resolved
Deploying flet-docs with
|
| Latest commit: |
ef9bc87
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7dc38c40.flet-docs.pages.dev |
| Branch Preview URL: | https://file-picker-client-upload.flet-docs.pages.dev |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds optional file content retrieval to the FilePicker API, addressing web platform limitations where filesystem paths are unavailable.
Changes:
- Added
with_dataparameter toFilePicker.pick_files()method (defaults toFalsefor backward compatibility) - Added
bytesfield toFilePickerFiledataclass to store file contents whenwith_data=True - Wired the feature through the Flutter
FilePickerServicewith mutually exclusivewithData/withReadStreamlogic - Added example demonstrating picking and saving text files using the new bytes-based API
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/services/file_picker.py | Added with_data parameter to pick_files(), added bytes field to FilePickerFile dataclass, implemented _normalize_file() to convert byte arrays from Dart |
| sdk/python/examples/services/file_picker/pick_and_save_text_content.py | New example demonstrating picking text files with with_data=True and reading/saving content via bytes |
| packages/flet/lib/src/utils/file_picker.dart | Added bytes field to FilePickerFile class and included in serialization |
| packages/flet/lib/src/services/file_picker.dart | Added withData parameter extraction and made withData/withReadStream mutually exclusive, included bytes in returned file payload when withData=True |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Addressed
Checks run:
|
Deploying flet-examples with
|
| Latest commit: |
ef9bc87
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0cec875e.flet-examples.pages.dev |
| Branch Preview URL: | https://file-picker-client-upload.flet-examples.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
with_dataargument toFilePicker.pick_files()in Python APIFilePickerFile.byteswhenwith_data=Truewith_datathrough FlutterFilePickerServiceand includebytesin returned file payloadsdk/python/examples/services/file_picker/pick_and_save_text_content.pydemonstrating:FilePickerFile.bytessave_file(src_bytes=...)Motivation
This improves web file handling where a filesystem path is unavailable and callers need file contents directly.
Discussion reference: #3146
Validation
dart analyze packages/flet/lib/src/services/file_picker.dart packages/flet/lib/src/utils/file_picker.dartuv run python -m compileall sdk/python/packages/flet/src/flet/controls/services/file_picker.py sdk/python/examples/services/file_picker/pick_and_save_text_content.pyPotentially related issues
FilePickerpath handling / inability to read selected file by path)path=Nonein picked files)This PR does not change the web
pathbehavior; it addsbytesopt-in as a supported alternative.Summary by Sourcery
Add optional file content retrieval to the file picker API and demonstrate its usage with a new Python example.
New Features:
Enhancements: