Android Camera - different base64 from web

Hi, I have an issue on the base64 format of the expo-camera being different on web and on android.

On web I have a base64 format like “data:image/png,base64,[…]”.
On android I have a base64 format like “/9j/[…]”

The problem come when I’m trying to display the image with the base64 (for local purpose) and when I try to get the image with the function “atob( base64 )”.

Can you help me figure out why the base64 is different and how to solve this?
If this topic is lacking some information please tell me, I will fix asap.

Thank you for the future help or improvement.

1 Like

Hello how are you?
How is your capture function code?
For example, in an expo-camera snap code I would use:

if (this.camera) {

const options = {

base64: true,

quality: 1

}

const photo = await this.camera.takePictureAsync(options);

if (photo) {

this.setState({ imageuri: photo.uri, modalUpload: true });

}

console.log(photo.uri)

}

my base64 returns the same uri option for all devices, (Android, iOS and web)

Hi,

many thanks for your reply.

In my code I already use the options you displayed, but I forgot to mention that on web I get a .png image, instead on Android I get a .jpg image.

Is there anything that I can do to make the Android camera getting .png instead of .jpg?
The problem comes when I’m trying to convert the base64 in binary using the library “base-64” for NodeJS.

1 Like

@fabrizio.gigli Hi, well, we have some ways to transform this image into png. You could use “ImageManipulator”, from the following documentation: ImageManipulator - Expo Documentation
Or you could also use “FileSystem”, which allows you to manipulate the uri of your captured image, follow the documentation: FileSystem - Expo Documentation
Any doubts you can feel free to ask, if I haven’t helped give the feedback I try to help you with something else. Hugs friend!

@fabrizio.gigli
Oops, I was looking here too. I believe you can change the image format by “FormData” as follows:

let formData = new FormData();
formData.append(“photo”, {
hi,
name: photo."png/jpeg",
type: image/"png/jpeg",
});