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).
npm install @missingcore/react-native-actual-path
Important
This might not work directly with the content://
URI returned from expo-file-system
's StorageAccessFramework.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;
}
}