ammarahm-ed / react-native-scoped-storage

MIT License
58 stars 10 forks source link

How to request permission for writing #12

Closed somasekharkakarla closed 2 years ago

somasekharkakarla commented 2 years ago

Hi, I am using scoped library. I am unable create file. It say you have no permission to create. Can you please how can I call permission. If possible please create a video tutorial on this.

ammarahm-ed commented 2 years ago

@somasekharkakarla to read/write you need to first call openDocumentTree and select the directory where files should be stored/read from. Then use the uri returned to create files.

Then you can use other functions.

somasekharkakarla commented 2 years ago

@ammarahm-ed can't i create like external directory, with out opening the document tree?

ammarahm-ed commented 2 years ago

No you cannot. You have to atleast call openDocumentTree and persist the uri. Then later if you want to reuse the same uri, call getPersistedUriPermissions and save/read file. That's how scoped storage works on android.

First time

let file = await ScopedStorage.openDocumentTree(true);
await ScopedStorage.writeFile(file.uri,"myfile.png");

Later

let uri = await ScopedStorage.getPersistedUriPermissions();
await ScopedStorage.writeFile(uri,"myfile.png");