Hello !
After a long day of research I can’t tranfer an image taken by my camera to my php API.
I tried some various tutorial (https://devdactic.com/ionic-2-images/) but I don’t reach my objective.
After that my code is so messy, so I clean it as well as possible. So do you have an idea to take a picture and to upload it on the server ?
Thanks you for your response.
takePicture() {
this.photo_link = '';
this.camera.getPicture({
quality: 100,
sourceType: this.camera.PictureSourceType.CAMERA
}).then((imagePath) => {
this.image = imagePath;
}
, (err) => {
console.log(err);
});
}
upload(id: number) {
var api = "myapi"+id;
const fileTransfer: TransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: 'photo',
fileName: 'image.jpg',
httpMethod: 'POST',
chunkedMode: false,
mimeType: "multipart/form-data",
}
alert("push photo");
fileTransfer.upload(this.image,api, options)
.then((data) => {
alert("success");
})
.catch((err) => {
alert("error photo" + JSON.stringify(err));
});
}