Hi, I’m very new in angular/ionic and I’m trying to display the images that I select from the Gallery (android) but it’s not working. I can select the image, but when it turns to display it, it won’t do that. Can you help me see what’s wrong in here? I’ve seen a lot of pieces of code, and they’re always almost the same, but I can’t make it work, so my only option is to reach you guys.
Here’s my code:
async selectArchive() {
const actionSheet = await this.actionSheetController.create({
header: "Select Image Source",
buttons: [{
text: 'Import from Library',
handler: () => {
this.selectImage();
}
},
{
text: 'Camera',
handler: () => {
this.takePhoto();
}
},
{
text: 'Cancel',
role: 'cancel'
}
]
});
await actionSheet.present();
}
takePhoto() {
var options ={
quality: 100,
mediaType: this.camera.MediaType.PICTURE,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG
}
this.camera.getPicture().then((imagedata) => {
let filename = imagedata.substring(imagedata.lastIndexOf('/')+1);
let path = imagedata.substring(0, imagedata.lastIndexOf('/')+1);
this.file.readAsDataURL(path, filename).then((basic64data) => {
this.images.push(basic64data);
console.log(imagedata);
})
})
}
selectImage() {
var options ={
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: false
}
this.camera.getPicture(options).then((imagedata) => {
let filename = imagedata.substring(imagedata.lastIndexOf('/')+1);
let path = imagedata.substring(0, imagedata.lastIndexOf('/')+1);
this.file.readAsDataURL(path, filename).then((basic64data) => {
this.images.push(basic64data);
console.log(imagedata);
})
})
}