@missingcore/react-native-actual-path
v0.1.0
Published
A utility package that attempts to get the actual path from content URIs.
Readme
@missingcore/react-native-actual-path
A port of react-native-actual-path that supports both the new & old architectures.
Also supports returning paths from the device's SDCard slot (tested using an emulator).
Installation
npm install @missingcore/react-native-actual-pathUsage
[!IMPORTANT] This might not work directly with the
content://URI returned fromexpo-file-system'sStorageAccessFramework.requestDirectoryPermissionsAsync(). Below is an example on how to get around this.
import { getActualPath } from '@missingcore/react-native-actual-path';
import { StorageAccessFramework as SAF } from 'expo-file-system';
export async function getDirLocation() {
const permissions = await SAF.requestDirectoryPermissionsAsync();
if (!permissions.granted) return null;
try {
const dirContents = await SAF.readDirectoryAsync(permissions.directoryUri);
const dirItem = dirContents[0];
if (!dirItem) throw new Error('No items found in directory.');
const resolved = await getActualPath(dirItem);
return resolved ? resolved.split('/').slice(0, -1).join('/') : null;
} catch (err) {
console.log(err);
return null;
}
}