2

I'm developing a React Native app for Android platform and I have to download file by using rn-fetch-blob library. I find out some apps can open File Manager of Android and choose a directory when user download. So how can I do that?

My app download using writeFile method because it's a base64, not using fetch file from url.

Thanks for reading question and have a nice day!

Rino
  • 53
  • 7

1 Answers1

4

You can use this package react-native-scoped-storage

import * as ScopedStorage from "react-native-scoped-storage"

let dir = await ScopedStorage.openDocumentTree(true);

Once the user selects a directory, we will recieve the information about the directory and its uri. Now we can use this uri to read/write.

// We can store this directory in AsyncStorage for later use.
await AsyncStorage.setItem('userMediaDirectory',JSON.stringify(dir));
Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47
  • thanks @Engr.Aftab Ufaq, it's work perfectly but when I download file next time, button "Use this folder" in File Manager is lost. I have to go back to previous folder and select destination folder again to see the button. Do you have any solution for this? – Rino Dec 23 '22 at 07:56
  • 2
    for this you have to save your path in some Aysnc Storage and then use that. – Engr.Aftab Ufaq Dec 23 '22 at 08:09