I am currently trying to develop a simple application using Expo and react-native and have run into a problem that i cannot overcome. I need to aquire pictures in the base64 format both using camera and from gallery. For this purpose I decided to use the ImagePicker expo component. When I access pictures form gallery using
const responsey = await ImagePicker.launchImageLibraryAsync({base64: true, quality: 1,});
It works like a charm, but when I try to access camera feed via
const response = await ImagePicker.launchCameraAsync({base64: true, quality: 1,});
The promise never resolves and the application is stuck waiting for it. I read in documentation about the ImagePicker.getPendingResultAsync() method and tried using is as such:
const prom1 = ImagePicker.launchCameraAsync({base64: true, quality: 1,});
const prom2 = ImagePicker.getPendingResultAsync();
response = await any([prom1,prom2]);
But the result of this is an empty array (I imagin returned instantly form the second promise) Where any is the function from promise.any package.
Additionaly I have noticed that when I don't request the base64 format the promise from launchCameraAsync resolves just fine. I am reunning the appliaction on Android 10.
I am struggling to resolve this problem and been stuck on int for several days, I would be gratefull for any advice or direction as to how to solve this.
Arrange your code like that to get the base 64 value.
const openCamera = async () => {
// Ask the user for the permission to access the camera
const permissionResult = await ImagePicker.requestCameraPermissionsAsync();
if (permissionResult.granted === false) {
alert("You've refused to allow this appp to access your camera!");
return;
}
const result = await ImagePicker.launchCameraAsync({
base64: true,
quality: 1,
});
// Explore the result
console.log(result.base64);
if (!result.cancelled) {
}
};
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