saveToCameraRoll failed with Permission denied
error on Android
Saving a AWS S3 photo to the device Camera Roll suddenly failed
RNFS.downloadFile(DownloadFileOptions)
.promise
.then(() => {
CameraRoll.saveToCameraRoll(path, this.state.type) // path = /data/user/0/com.XXX.app/filesimage-xyz.jpg"
.then((data) => {
RNFS.unlink(path)
.then(() => {
console.log('Download and file unlink succeeded');
})
.catch((err) => {
console.error("RNFS unlink error: ", err.message);
});
})
.catch((error) => {
console.error("Save to Cameral roll error: ",error.message);
//error = code:"EUNSPECIFIED"
// framesToPop:1
// message:"Permission denied"
// stack:"Error: Permission denied↵
});
})
.catch((error) => {
console.error("RNFS.downloadFile! error: ", error.message);
});
In the android/app/src/main/AndroidManifest.xml i have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
among few other permissions.
What can cause a permission denied error ? what shall be done at the Manifest level to save to cameraRoll ?
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. You can use PermissionAndroid API to let users to grant permission for external storage access.
Example:
requestExternalStoragePermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'My App Storage Permission',
message: 'My App needs access to your storage ' +
'so you can save your photos',
},
);
return granted;
} catch (err) {
console.error('Failed to request permission ', err);
return null;
}
};
You can try:
...
let permission = await Expo.Permissions.askAsync(Expo.Permissions.CAMERA_ROLL);
if (permission.status === 'granted') {
await CameraRoll.saveToCameraRoll(fileUrl, "photo");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With