packages icon indicating copy to clipboard operation
packages copied to clipboard

[cross_file] Adds proper openRead for web.

Open ditman opened this issue 2 years ago • 2 comments


[!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.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • [ ] I updated CHANGELOG.md to 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.

ditman avatar Oct 17 '23 02:10 ditman

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

ditman avatar Jan 10 '24 00:01 ditman

Still blocked by the Platform-aware factories issue linked above.

ditman avatar Mar 12 '24 22:03 ditman

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.

jackie099 avatar Mar 19 '24 22:03 jackie099

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)

ditman avatar Mar 19 '24 23:03 ditman

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.

rohintoncollins avatar May 15 '24 14:05 rohintoncollins

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

ditman avatar Jul 16 '24 17:07 ditman