Skip to content
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

Support saving images to the origin private file system on Js and wasmJs. #1951

Open
colinrtwhite opened this issue Dec 13, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Issues that are up for grabs + are good candidates for community PRs

Comments

@colinrtwhite
Copy link
Member

colinrtwhite commented Dec 13, 2023

This is out of date. See below.

Is your feature request related to a problem? Please describe.
One of the downsides of running Kotlin Multiplatform code on browser-based Javascript is that it's not possible to read from or write to the device's file system. Currently, that means NetworkFetcher can't cache images on disk and can only store them in memory.

Describe the solution you'd like
Due to the nature of browser-based Javascript, it's not possible to write a FileSystem implementation for Javascript. As such it's not possible to write a Ktor response body to disk. This means we need to write a separate fetcher since we can't rely on Ktor or Okio.

The <img> tag in Javascript has special privileges to write to a disk cache on browsers. Using this tag we may be able to fetch the image data using a hidden <img> tag and then read and wrap its binary data as an ImageSource. Ideally, we would avoid the <img> tag decoding the image into memory, but I'm not sure if that's possible.

Additional context
This may or may not happen as there might be blockers or performance issues. I'm not very familiar with the web's APIs and their constraints.

@colinrtwhite colinrtwhite added enhancement New feature or request help wanted Issues that are up for grabs + are good candidates for community PRs 3.0 labels Dec 13, 2023
@colinrtwhite
Copy link
Member Author

On second thought this probably isn't a great idea. We're better off using the origin private file system, though that has separate challenges since it needs to be called asynchronously but Okio's FileSystem abstraction only has synchronous APIs.

@colinrtwhite colinrtwhite removed the 3.0 label Jul 31, 2024
@colinrtwhite colinrtwhite changed the title Javascript network url fetcher backed by <img> tag Support saving images to the origin private file system on Js and wasmJs. Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Issues that are up for grabs + are good candidates for community PRs
Projects
None yet
Development

No branches or pull requests

1 participant