I’m capture Image using ionic native camera and show image on UI but not able to upload base64 image on server (Post Api).
this my code.
captureImage() {
const options: CameraOptions = {
quality: 70,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
// saveToPhotoAlbum: true,
};
this.camera.getPicture(options).then((imageData) => {
console.log(‘api =>’, imageData);
this.selectedFile = “data:image/jpeg;base64,” + imageData;
this.photos?.push(this.selectedFile);
this.photos.reverse();
}, (err) => {
console.log('ERROR → ', (err));
});
}
save() {
const postData = new FormData();
for (let i = 0; i < this.selectedFile.length; i++) {
postData.append(‘file’, this.selectedFile[i]);
}
this.http.post(this.url, postData).subscribe(async resimage => {
console.log(resimage);
const toast = await this.tostController.create({
message: ‘Almost done! Your product will be shown shortly after approval.’,
color: ‘success’,
position: ‘middle’,
duration: 3000
});
toast.present();
});
this.router.navigateByUrl(‘/home’);
}