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

Android: Proper way to download a file for user media consumption #380

Open
PaperbagWriter opened this issue Aug 28, 2024 · 1 comment
Open
Labels
documentation Improvements or additions to documentation

Comments

@PaperbagWriter
Copy link

PaperbagWriter commented Aug 28, 2024

Versions:

react-native-blob-util: "0.19.11",
react-native: "0.73.9"

I'm confused about what is the best way to download a file on Android on different versions and for this media to be accessible in the Download apps or the Gallery apps. For the regular downloads internally to the app everything I think is pretty straight forward but for the above use case, the doc is very ambiguous.

From the doc I got the impression that from Android version 10 and upwards we should use copyToMediaStore. This works but makes it so that the downloadManager won't point to the file upon completion (downloads to cache then copies), so I need to skip the download manager.

For the versions below 10 we should use a path such as ReactNativeBlobUtil.fs.dirs.LegacyDCIMDir.

My confusion comes from the fact that I'm able to download to ReactNativeBlobUtil.fs.dirs.LegacyDCIMDir without using the copyToMediaStore on all Android versions (9-13). Is there a reason why I should not do that (and it is considered legacy)?

This also avoids having unwanted cached files, downloading directly to the internal storage InternalStorage/DCIM.

The documentation is pretty non-existent for Android below 10 so I wanted to update it, but because of the confusion, I did not.

Thanks

@PaperbagWriter PaperbagWriter changed the title Proper way to download on Android Android: Proper way to download a file for user media consumption Aug 28, 2024
@RonRadtke
Copy link
Owner

It all boils down to what you want your user to do.
ReactNativeBlobUtil.fs.dirs.LegacyDCIMDir is private to your app. So it will not show int he users gallery, or downloads for the other paths.
If you want the file to be visible in the gallery / downloads folder, you have to use the media store api on Android > 10.
For Android < 10 you can download the file to the downloaddir, or you use the Android Downloadmanager.

The android downloadmanager can also be used for Android > 10. But the API for it to add files to the downloads folder is deprecated, so unsure how long we can use it.

@RonRadtke RonRadtke added the documentation Improvements or additions to documentation label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants