alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
307 stars 19 forks source link

[Q] Fetch #13

Open sayem314 opened 3 years ago

sayem314 commented 3 years ago

Thanks for the library. I just found it today. I have few questions.

alpha0010 commented 3 years ago

The focus of this library is filesystem actions. For more advanced upload/download control, consider https://github.com/edeckers/react-native-blob-courier, it focuses on network, ignoring filesystem, so would compliment this library well.

I have not used react-native-blob-courier myself (so cannot vouch for actual functionality), but from the documentation, appears to handle the features you are looking for.

sayem314 commented 3 years ago

Thank you for your response. I will check out the package you mentioned however I would still suggest adding a background download feature with pause and resume since you are providing a fetch option.

efstathiosntonas commented 3 years ago

Hi @alpha0010, we've recently released https://github.com/georstat/react-native-image-cache, it would be nice to have resumable downloads like: https://github.com/wcandillon/react-native-expo-image-cache/blob/b81b99b01918558c7680595980d76003d507bc6f/src/CacheManager.ts#L29 in order to "improve" it.

We hope/believe that it will get lot of traction.

Thanks

alpha0010 commented 3 years ago

I looked a bit deeper into this.

Using the system managed downloader might take a bit of work, but should be reasonably straight forward implementation.

App managed pause/resume for downloads would be more complicated. Would need to manage HTTP range requests, and handle servers that do not understand/obey them. On the plus side, this may be possible to implement js/ts side (on top of the existing APIs in this library), so might only need to implement once. Although, native side would be a bit more performant.

Download progress events would need to be emitted from native code for higher resolution. I suppose rough events could be triggered from js if implemented range requests there.

Not currently a priority for me, though I hope to look into at some point. Of course, accepting pull requests if you wish to help.

efstathiosntonas commented 3 years ago

Thanks for looking into it, I have no clue on native code so I can’t help on this part.

I think everything should be done on native side as you stated. How are the other react native file system libs are handling such cases? (expo fs too)

alpha0010 commented 3 years ago

Expo constructs headers on Android

And on iOS, there is apparently a convenient native call https://developer.apple.com/documentation/foundation/nsurlsession/1411598-downloadtaskwithresumedata

alpha0010 commented 3 years ago

Added progress events in branch https://github.com/alpha0010/react-native-file-access/tree/download-progress . I plan to test a bit more before tagging a release.

efstathiosntonas commented 3 years ago

Thanks @alpha0010, if you want we can test too with the caching lib in real apps.

alpha0010 commented 3 years ago

Thanks. Just published, but of course if you notice any bugs in your testing/use, open an issue here.

Download progress updates live in 1.7.0.

ezze commented 2 years ago

Unfortunately, react-native-blob-courier doesn't support passing body to fetchBlob at the moment and FileSystem.fetch doesn't support request cancel. So none of both suits our requirements — we need to pass body to fetch request and have an option to cancel it because big amount of data is transferred. Would be awesome if we could add missing options, guys.

alpha0010 commented 2 years ago

Thanks for your interest. To confirm, passing request body works for you (when using this library), but it is missing request cancel? Background architecture for supporting cancels is already there. I just ran out of time before wiring it in. Will try to get to that soon.

ezze commented 2 years ago

@alpha0010 Thanks for reply. Yes, I use your library to download blobs right now because it supports passing a body to request. And I use react-native-blob-courier to upload blobs due to it supports request cancel.

alpha0010 commented 2 years ago

Published a release; let me know how it works for you.

ezze commented 2 years ago

@alpha0010 Cool, it was very fast reaction, mate!

But I am sorry, can't test it this time. Already implemented a workaround with react-native-blob-courier suitable for me at the moment. Anyway, I am still using react-native-file-access to work with file system so I'll definitely check it later.

Nirav-12 commented 1 year ago

Thanks for the library.

Any possibility to add support for copy progress ( FileSystem.cp)?