I am attempting to retrieve the base64 string of an image file URI using '@ionic-native/base64' from '@ionic-native/image-picker', but it seems that the image is broken after running this code. Are there any suggestions on how to fix this?
Here is my HTML:
<img [src]="base64ImageChosen" *ngIf="base64ImageChosen"/>
These are my picker options:
this.pickerOptions = {
maximumImagesCount: 1,
width: 10,
height: 10,
quality: 100,
outputType: 0
};
This is my code snippet:
chooseImage() {
this.imagePicker.getPictures(this.pickerOptions).then((results) => {
for (let i = 0; i < results.length; i++) {
let filePath: string = results[i];
this.base64.encodeFile(filePath)
.then((base64File: string) => {
this.base64ImageChosen = base64File
}, (err) => {
console.log(err);
})
.then((res) =>
this.myForm.patchValue({ imageChosen: this.base64ImageChosen })
)
}
}, (err) => { });
}