Camera photo to base64

I am having some problems converting camera image to base64. Maybe any of you can help me with that. I will appreciate that.

Welcome to Ionic Forum. Some advice to help you and help others to help you:

  • Please, when sharing some problem related to a code, don’t post an image of it, post the code itself and format it with the tools provided in the text box.
  • Post the errors you are getting while using your method, no images too, just the formatted error message.
  • Comment what you already tried and searched and why it didn’t work.

The forum has a pinned post that explain this. You can also check here to more tips. Following this tips increase your chances of getting a good answer for your question and prevents duplicate questions.

1 Like

Camera service already can read file as base64.

private takePhoto():void {
    let camermaOptions: CameraOptions = {
      quality: 70,
      destinationType: this.camera.DestinationType.DATA_URL,
      sourceType: 2,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      correctOrientation: true,
      targetWidth: 1920,
      targetHeight: 1080
    };

    this.camera.getPicture(camermaOptions).then((imageData) => {
      this.imageBase64 = 'data:image/jpeg;base64,' + imageData;
      // do something
    }, (err) => {
      this.dismiss();
    });
  }

Hello @sonichk Sonichk thanks for your answer, but this function only allows me to select the picture from the library, do you know How can I activate the camera functions to take the picture?

Hello @leonardofmed, thanks for the recomendations i will consider in future questions.
Regards

1 Like