Starting in Android 11, apps that use the scoped storage model can access only their own app-specific cache files. As soon as React Native targets API 30, all of us will have to use Scoped Storage to access any files stored in the sdcard/phone storage. This library provides an API for react-native devs to start testing out scoped storage in their apps. Remember, you do not need
WRITE_EXTERNAL_STORAGE permission in you
AndroidManifest.xml file using this library.
Scoped storage allows you to prompt the user that you need access to some file/folders. The user can the allow access to their desired location. It is your responsibility to store the uri you recieve for later use.
Important note: Until React Native targets API 29, you do not need this library. However you should start testing it out in your apps/projects because soon, we will have to move to this new API for file access.
Install the library
yarn add react-native-scoped-storage
npm install react-native-scoped-storage
Ƭ FileType: object
|string||data read from the file|
|number||Last modified date of the file or directory|
|string||mime type of the file|
|string||Name of the file or directory|
|string||Storage path for the file|
|string||Document Tree Uri for the file or directory|
Defined in: index.tsx:5
dirName: string): Promise<FileType>
Create a new directory under a parent uri.
|string||Uri of the parent directory|
|string||Name of the directory to create|
Defined in: index.tsx:111
Open Document picker to create a file at the user specified location.
|string||Name of the file to create.|
|string||mime of the file to create. eg image/jpeg|
|string||Data to write to the file once it is created.|
|Encoding of the dat you are writing.|
Defined in: index.tsx:37
uri: string): Promise<boolean>
Delete a file or directory at the given path.
|string||Path to the file or directory to delete|
Defined in: index.tsx:99
▸ getPersistedUriPermissions(): Promise<string>
There is a limit to the number of uri permissions your app can persist. Get a list of all the persisted document tree uris so you are remove the ones you are not using or perform other operations.
Defined in: index.tsx:54
uri: string): Promise<FileType>
List all files and folders in a directory uri
|string||Path to a directory.|
Defined in: index.tsx:72
readData: boolean): Promise<FileType>
Open Document picker for the user to select a file.
|boolean||Do you want to read data from the user specified file?|
Defined in: index.tsx:46
▸ openDocumentTree(): Promise<FileType>
Open the Document Picker to select a folder. Read/Write Permission will be granted to the selected folder.
Defined in: index.tsx:25
uri: string): Promise<string>
Read file at a given path. The path of the file must be a document tree uri.
|string||Path to the file you want to read.|
Defined in: index.tsx:81
uri: string): Promise<void>
Remove a uri from persisted uri list.
|string||The uri you want to remove from persisted uri permissions.|
Defined in: index.tsx:63
name: string): Promise<string>
Rename a file or directory at the given path.
|string||Path to the file or directory to rename|
|string||New name for the file or directory|
Defined in: index.tsx:91
append: boolean): Promise<boolean>
Write to a file at the given directory. If the file does not exist, it will be created.
|string||Uri of the directory|
|string||Name of the file|
|string||Mime of the file. eg image/jpeg|
|string||Data you want to write|
|Encoding of the data you are writing.|
|boolean||Should the data be appended to the existing data in file?|
Defined in: index.tsx:112
That is awesome news! There is alot happening at a very fast pace in this library right now. Every little help is precious. You can contribute in many ways:
This library is licensed under the MIT license.
Copyright © Ammar Ahmed (@ammarahm-ed)