I'm clicked image successfully by ionic Cordova Native Camera but not able to upload on server (post API) please help me to solve this problem. as soon as possible.
this is my code.
captureImage() {
Const options: Camera Options = {
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');
}