packages
                                
                                 packages copied to clipboard
                                
                                    packages copied to clipboard
                            
                            
                            
                        [cross_file] Adds proper openRead for web.
[!WARNING]
Blocked by:
- https://github.com/flutter/flutter/issues/91869
This PR adds a BlobStream class that allows cross_file users to read large blobs from a Stream.
Issues
- Fixes: https://github.com/flutter/flutter/issues/91867
Tests
(TBD, solution under verification internally!)
Pre-launch Checklist
- [ ] I read the Contributor Guide and followed the process outlined there for submitting PRs.
- [ ] I read the Tree Hygiene wiki page, which explains my responsibilities.
- [ ] I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
- [ ] I signed the CLA.
- [ ] The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
- [ ] I listed at least one issue that this PR fixes in the description above.
- [ ] I updated pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
- [ ] I updated CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.
- [ ] I updated/added relevant documentation (doc comments with ///).
- [ ] I added new tests to check the change I am making, or this PR is test-exempt.
- [ ] All existing and new tests are passing.
If you need help, consider asking for advice on the #hackers-new channel on Discord.
This PR requires cross_file to be created directly from a browser blob, without moving data around.
In order to implement that constructor, we need this first:
- https://github.com/flutter/flutter/issues/91869
Still blocked by the Platform-aware factories issue linked above.
Thanks for the work!
Is there a temp fix before this is merged? I'm trying to construct MultipartFile with streams on flutter web and seeing memory issues with large files.
Is there a temp fix before this is merged?
Not yet, the problem is how cross-files are constructed on the web; they always end up allocating a big array to move their blob contents around, and that's BAD for performance.
(See the issue that is blocking this PR for more details)
I have gotten around this (in part) by using the File System API (https://developer.mozilla.org/en-US/docs/Web/API/File_System_API#browser_compatibility), package: file_system_access_api. This has good support on Chrome and Edge, but not so good on Safari and Firefox. You can invoke a filePicker() and folderPicker() which gives you FileSystemHandles. From these handles you can get an html.File which can then be sliced to create a stream. I have this working and tested on Chrome and Edge. If anyone needs some example code, let me know.
I'm going to close this PR since it's still blocked, I'll revisit when we solve https://github.com/flutter/flutter/issues/91869