I am making use of Ionic Capacitor with the Camera plugin to upload an image to my ionic app. After getting the image I want to store the base64 string in a variable. My problem is that this only works if the image source is the camera, and not if the image source is the Gallery/Photos.
Here is my code:
async selectImageSource() {
const buttons = [
{
text: "Take Photo",
icon: "camera",
handler: () => {
this.addImage(CameraSource.Camera);
},
},
{
text: "Gallery",
icon: "image",
handler: () => {
this.addImage(CameraSource.Photos);
},
},
];
const actionSheet = await this.actionSheetCtrl.create({
header: "Select Image Source",
buttons,
});
await actionSheet.present();
} // End of select image source
async addImage(source: CameraSource) {
console.log("I clicked on Gallery");
const image = await Camera.getPhoto({
quality: 60,
allowEditing: true,
resultType: CameraResultType.Base64,
source,
});
this.Logo = "data:image;base64," + image.base64String;
console.log(this.Logo);
// this.InjectImage();
}
In the addImage method, the console.log at the very bottom of the method will not show if the image source is Photos/Gallery, but it does show if the image source is the camera.
In the AddImage method, the firdt console.log does appear in the console (when I use the gallery/photos option) but the second console.log does not appear.