react-nativeexpoexpo-camera

expo-camera returns invalid base-64 encoded image


Whenever I try to take a picture using expo-camera it returns an invalid base64 encoded string.

const {base64} = await cameraRef.takePictureAsync(options={base64:true,quality:0});
console.log(isBase64(base64)); // returns false

I checked, the variable base64 seems to hold a base64 encoded string. But if I try to use it, it is proved to be invalid. Does anyone have a fix?


Solution

  • The base64 returned from the camera has an issue, all the plusses are replaced with spaces. To get a valid base64 string all you have to do is replace all occurrences of spaces with plusses. base64=base64.replaceAll(" ","+")