File Upload Error in ionic 2

Hello,

I am new in ionic i am trying to upload file(images,pdf,doc) in server .
i have used ionic file transfer plugin .not able to upload file any one help me please.!
uploaderr

var a = this.file.externalDataDirectory + ‘images.jpg’;
this.fileTransfer.upload(a,encodeURI(url))
.then((data) => {
let alert = this.alertCtrl.create({
title: ‘Message’,
subTitle: “Success”,
buttons: [‘Dismiss’],
});
alert.present();
}, (err) => {
let alert = this.alertCtrl.create({
title: JSON.stringify(err.code),
subTitle: JSON.stringify(err),
buttons: [‘Dismiss’],
});
alert.present();
});

Thank you in advance please help me i have lot’s searching on google but no solution work for me.

in your error log shows that
http status 405… check with api receiving end once
and this worked me for upload file to server

 const fileTransfer: FileTransferObject = this.transfer.create();
          let optionsFile: FileUploadOptions = {
            fileKey: 'file',
            fileName: this.filenamegot,
            headers: {
              "Authorization":"your token"
            
            },
            chunkedMode: false

          }

          fileTransfer.upload(this.fileurl, URL to upload file to server , optionsFile)
            .then((data) => {
                      console.log("success upload")
                  }(error)=>{
                          console.log("Error handling ")
                       })

HI
Thank you for your response.
my url=‘url to upload file server/upload’ like this if i remove ‘/upload’ folder then file transfer return success but in server i can’t find my file.

Any solution i can’t understand what is the issue.

Thank you

attached my code here can you please look at

saveAttachment() {
let hosedata = Object.assign({}, this.form.value);
var a = this.file.externalDataDirectory + ‘images.jpg’;
var options = {
fileKey: ‘pic’,
fileName: ‘krishna.jpg’,
mimeType: “image/jpeg”,
chunkedMode:false,
params: { ‘model’: hosedata }
}

    this.fileTransfer.upload(a,"URL/Upload/",options,true)
        .then((data) => {
            let alert = this.alertCtrl.create({
                title: 'Message',
                subTitle: "Success",
                buttons: ['Dismiss'],
            });
            alert.present();
        }, (err) => {
            let alert = this.alertCtrl.create({
                title: JSON.stringify(err.code),
                subTitle: JSON.stringify(err),
                buttons: ['Dismiss'],
            });
            alert.present();
        });
}

debug with API server end and just check removing “/upload” with debugger .
in your case

Hi,

Yes, i have checked it present success alert but in my server i can’t found any file

Thank you