Hello,
I try transfer image with file Transfer plugin to api php but when i check if file has transfer or not … I have a empty array in php:
code ts:
uploadFile() {
var headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
let loader = this.loadingCtrl.create({
content: "Uploading..."
});
var fileTransfer: FileTransferObject = this.transfer.create();
if(this.images.length >0){
loader.present();
for(var x=0;x<=this.images.length-1;x++)
{
if (this.images[x] !== "K" && this.images[x] !== "O") {
this.base64.encodeFile(this.images[x]).then((base64File: string) => {
fileTransfer.upload(base64File, 'https://6c15a567.ngrok.io/wetry-api/web/upload', {
fileKey: 'ionicfile'+x,
fileName: 'ionicfile'+x,
chunkedMode: false,
mimeType: "image/jpeg",
headers: {}
})
.then((data) => {
this.presentToast("success upload");
this.presentToast(data.response);
}, (err:FileTransferError) => {
loader.dismiss();
this.presentToast("error upload");
this.presentToast(err.exception);
});
}, (err) => {
this.presentToast(err);
this.presentToast('error encode');
});
}
if(x === this.images.length) { loader.dismiss(); }
}
} else this.presentToast("please select images");
}
now how to resolve this error and transfer file