react-native-cameraroll: I can successfully save the photo to album but an error would pop up : Unknown error from a native module
Hi guyz π I can successfully save the photo to album but an error would pop up ( see the bottom of the post ),
my version installed in package.json : β@react-native-camera-roll/camera-rollβ: β^7.5.2β
if I comment out the following ( save to camera-roll part ), no error would show up, with / without βawaitβ keyword :
For example, I can console logged the uri : uri: file:///private/var/mobile/Containers/Data/Application/746DABFE-E230-4180- A986-8B607940951A/tmp/99E8D94D-1B69-467F-9269-97A92DAA7FE1.jpeg
I am following react-native-vision-camera documentation example code to implement react-native-cameraroll library, let me know if I need to put file://${photo.path} or just βuriβ variable is fine ( I tried both, both can successfully saved the photo to album, but both got the same error ) :
https://react-native-vision-camera.com/docs/guides/taking-photos
My code :
( I keep adding try-catch block because of the errors, it got the Error 1 : Possible unhandled promise rejection ( id : 0 ): Error : Unknown error from a native module
and after I added try-catch block, it got Error 2: Error saving photo asset : Unknown error from a native module )
try{
// await CameraRoll.saveAsset(`file://${photo.path}`, {
await CameraRoll.saveAsset(uri, {
type: 'photo',
});
Whole code block looks like this :
const onTakePicture = async() =>{
try {
const photo = await camera.current?.takePhoto({
// flash: 'auto'
});
// console.log("photo:", photo);
const uri = photo.path;
console.log("uri:", uri);
try{
// await CameraRoll.saveAsset(`file://${photo.path}`, {
await CameraRoll.saveAsset(uri, {
type: 'photo',
});
}catch (error) {
console.error('Error saving photo asset:', error);
// Handle the error here, such as displaying an error message to the user or logging the error for further investigation
}
} catch (error) {
console.error("Error while taking or saving photo:", error);
// Handle the error here, such as displaying an error message to the user or logging the error for further investigation
}
};
Error 1 :
Error 2 :
Let me know if you need detailed Logcat or these are enough for the clues
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 5
- Comments: 18
The additional permission prompt appears when the library tries to retrieve information about a saved asset. I managed to work around this with the following patch
@cristinaITdeveloper Using
PHOTO_LIBRARYinstead ofPHOTO_LIBRARY_ADD_ONLYmay help you. Something likes below:So, checking for permissions fixes the issue? We can close this then?