i have issue when i use the plugin and try to decode the img in the base64
My code
getimage(Type){
let options: CameraOptions;
if (Type == ‘camera’) {
options = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
} else if (Type == ‘gallery’) {
options = {
sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
}
this.camera.getPicture(options).then((img) => {
let base64 = ‘data:image/jpeg;base64,’ + img;
let data = {
token : this.api.token,
picture: base64
}
this.loading = this.loadingCtrl.create({
content: <ion-spinner name="bubbles" ></ion-spinner> Chargement...
});
this.loading.present();
this.api.post(‘media/upload’,data).toPromise().then((res) => {
this.loading.dismiss();
if (res[‘status’] == 200) {
let alert = this.alertCtrl.create({
title: ‘Information’,
subTitle: ‘Image ajouté avec succès’,
buttons: [{text:‘OK’}]
});
alert.present();
}else
{
let alert = this.alertCtrl.create({
title: res[‘status’],
buttons: [‘Ok’]
});
alert.present();
}
}).catch((e) => {
let alert = this.alertCtrl.create({
title: e.message,
buttons: [‘Ok’]
});
alert.present();
});
});
}