Rino
Rino

Reputation: 63

How to open File Manager and pick a directory before downloading file in React Native

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!

Upvotes: 2

Views: 2473

Answers (1)

Engr.Aftab Ufaq
Engr.Aftab Ufaq

Reputation: 6424

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));

Upvotes: 4

Related Questions