Skip to content

FileService: a way to work with file at frontend #656

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

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

catap
Copy link
Contributor

@catap catap commented Sep 20, 2020

The usecase of this code is something like this: let image that user is making a protonmail or any another application where content inside frontend (=browser storage) some secret user's data that shouldn't be exposed to backend. Secret key for example or anything like that.

This code allows to developer to convert any Seq[Array[Byte]] from frontend to URL as simple call FileService.createURL, asynchronously convert any uploaded File to Future[Array[Byte]] as FileService.asBytesArray, or to Array[Byte] via FileService.asSyncBytesArray inside worker.

Unfortunately scalatags doesn't support download attribute and I need to make it by hand. I've opened a PR1 to introduce it, but it might be a while until it is included to release.

FileService.asSyncBytesArray is using FileReaderSync that is also missed inside scala-js-dom. I've opened a PR2 but it might be a while. Also, this draft API but it is supported by majority of modern browsers3.

Footnotes

  1. https://github.com/lihaoyi/scalatags/pull/212

  2. https://github.com/scala-js/scala-js-dom/pull/424

  3. https://caniuse.com/?search=FileReaderSync

@catap catap force-pushed the save-bytes-as-file branch from e92d4bc to f3ac0f6 Compare September 20, 2020 21:42
@catap catap changed the title Introduced a simple way to save any bytes array as file from frontend Introduced a simple way to work with files inside frontend Sep 20, 2020
@ddworak ddworak self-requested a review September 22, 2020 05:57
Copy link
Member

@ddworak ddworak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, it's surely a tricky API use case we could cover for future users. It needs some more love before we ship it.

@catap catap force-pushed the save-bytes-as-file branch from f3ac0f6 to 762c992 Compare September 28, 2020 22:54
@catap catap requested a review from ddworak September 28, 2020 22:55
@catap
Copy link
Contributor Author

catap commented Sep 28, 2020

@ddworak I have no idea when to revoke this URL. If you have some, feel free to share.

@catap catap force-pushed the save-bytes-as-file branch 6 times, most recently from 9a7f575 to 93b95be Compare September 30, 2020 20:13
@catap catap marked this pull request as draft October 1, 2020 08:33
@catap catap force-pushed the save-bytes-as-file branch 2 times, most recently from e223de8 to 414b03f Compare October 1, 2020 20:21
@catap catap force-pushed the save-bytes-as-file branch from 414b03f to 53a6021 Compare November 16, 2020 11:41
@catap catap marked this pull request as ready for review November 16, 2020 11:41
@catap
Copy link
Contributor Author

catap commented Nov 29, 2020

@ghik, @ddworak any chance to review? ;)

@catap catap force-pushed the save-bytes-as-file branch from 53a6021 to 5e2b8ed Compare December 2, 2020 21:07
@catap catap changed the title Introduced a simple way to work with files inside frontend FileService: a way to work with file at frontend Dec 2, 2020
@catap catap force-pushed the save-bytes-as-file branch 2 times, most recently from 0d90a27 to 46da6eb Compare December 2, 2020 21:50
@catap catap requested a review from ddworak December 2, 2020 22:44
@catap catap force-pushed the save-bytes-as-file branch from 46da6eb to d950c0c Compare December 6, 2020 14:22
@catap catap force-pushed the save-bytes-as-file branch from d950c0c to 9b86e13 Compare December 6, 2020 22:14
@catap catap requested a review from ddworak December 6, 2020 22:15
@catap catap force-pushed the save-bytes-as-file branch from 9b86e13 to 0111442 Compare December 6, 2020 22:36
Copy link
Member

@ddworak ddworak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor rename, thanks!

The usecase of this code is something like this: let image that user is making a
protonmail or any another application where content inside frontend (=browser
storage) some secret user's data that shouldn't be exposed to backend. Secret
key for example or anything like that.

This code allows to developer to convert any `Seq[Array[Byte]]` from
frontend to URL as simple call `FileService.createURL`, asynchronously
convert any uploaded `File` to `Future[Array[Byte]]` as
`FileService.asBytesArray`, or to `Array[Byte]` via
`FileService.asSyncBytesArray` inside worker.

Unfortunately scalatags doesn't support `download` attribute and I need
to make it by hand. I've opened a PR[^1] to introduce it, but it might be a
while until it is included to release.

`FileService.asSyncBytesArray` is using `FileReaderSync` that is also
missed inside scala-js-dom. I've opened a PR[^2] but it might be a
while. Also, this draft API but it is supported by majority of modern
browsers[^3].

[^1]: com-lihaoyi/scalatags#212

[^2]: scala-js/scala-js-dom#424

[^3]: https://caniuse.com/?search=FileReaderSync
@catap catap force-pushed the save-bytes-as-file branch from 0111442 to 9c1d9a2 Compare December 7, 2020 09:13
@catap
Copy link
Contributor Author

catap commented Dec 7, 2020

@ddworak pushed renaming.

@ddworak ddworak added this to the 0.9.0 milestone Dec 7, 2020
@ddworak ddworak merged commit 4a602c5 into UdashFramework:master Dec 7, 2020
@catap catap deleted the save-bytes-as-file branch December 8, 2020 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants