Registry / storage / react-native-scoped-storage

react-native-scoped-storage

JSON →
library1.9.5jsnpmunverified

A React Native library (v1.9.5) that provides an API for accessing Android's Scoped Storage, required for apps targeting API 30+. It allows reading/writing files in user-selected directories without WRITE_EXTERNAL_STORAGE permission. Uses the Storage Access Framework (SAF) via document tree pickers and persisted URI permissions. Actively maintained, weekly releases on npm. Key differentiator: handles scoped storage complexities that React Native's built-in FS module lacks.

npm install react-native-scoped-storage
INSTALL
IMPORT
SIG · REACT-NATIVE-SCOPE
R
react-native-scoped-storage
storagejavascriptv1.9.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ScopedStorage
import * as ScopedStorage from 'react-native-scoped-storage'
import ScopedStorage from 'react-native-scoped-storage'
Namespace import required for TypeScript types; default export not available.
openDocumentTree
import { openDocumentTree } from 'react-native-scoped-storage'
const { openDocumentTree } = require('react-native-scoped-storage')
Named import works; require is CommonJS and not recommended in RN projects.
writeFile
import { writeFile } from 'react-native-scoped-storage'

Shows how to request a directory, persist permission, write and read a file in scoped storage.

import * as ScopedStorage from 'react-native-scoped-storage'; async function saveImage() { // Request user to select a directory const dir = await ScopedStorage.openDocumentTree(true); // Persist access for future use await ScopedStorage.persistPermission(dir.uri); // Write a file const base64Data = 'iVBORw0KGgoAAAANSUhEUg...'; await ScopedStorage.writeFile(dir.uri, 'image.jpg', 'image/jpeg', base64Data, 'base64'); // Read it back const fileContent = await ScopedStorage.readFile(dir.uri, 'image.jpg', 'base64'); console.log('File saved and read successfully'); }
Debug
Known issues
breakingAndroid 11+ requires AppAuth or direct file path access is forbidden
fix
Always use user-selected URIs; never assume you can access arbitrary paths.
affects: >=0.0.0
gotchaURIs are temporary unless you persist permission
fix
Call ScopedStorage.persistPermission(uri) after user grants access.
affects: >=0.0.0
gotchaFile name can change when using createDocument
fix
Use the returned file object's name, not the one you passed.
affects: >=0.0.0
deprecatedRead/write using file path strings deprecated in favor of URIs
fix
Always use URI-based methods: readFile, writeFile with parentUri.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'openDocumentTree' of undefined
Namespace import not used; tried named import incorrectly.
fix
Use `import * as ScopedStorage from 'react-native-scoped-storage'`
EACCESS: permission denied, open '/storage/emulated/0/...'
Attempting to access file path directly without SAF
fix
Use ScopedStorage.readFile or writeFile with a URI.
Upgrade
Version history
1.9.5latest on npm
Audit
Dependencies
react-nativerequiredPeer dependency required
Agent activity
21 hits · last 30 days
node
18
Amazon
1
Resources
react-native-scoped-storage — npm install react-native-scoped-storage · libregistry