Ionic 2 FileTransfer.download showing error code 1

 let fileTransfer = new Transfer();
      fileTransfer.download("http://my.server.com/download?path=filelocationWithDifferentName, cordova.file.externalDataDirectory + ActualFileName).then((entry) => {

        this.showToast("Download Completed");
        this.openReport(file);

      }, (error) => {

        const alertFailure = this.alertCtrl.create({
          title: `Download Failed!`,
          subTitle: `${file} was not successfully downloaded. Error code: ${error.code}`,
          buttons: ['Ok']
        });

        alertFailure.present();

      });

    });

Above is my code. after downloading server send file with actual file name. I tested it on android it showing error code 1.
Anybody knows the solution.

Error code 1 means that it couldn’t find the file:
https://github.com/apache/cordova-plugin-file-transfer#constants

1 Like

The docs tell you how to use the Transfer plugin. It does not include instantiating Transfer objects with new.

Is he using Ionic Native? Maybe he is just winging it with the plugin directly. ALthough, then he should probably switch to Ionic Native!

Thanks… It worked
Forgot to encode Url

how to do it.
can you help me

var uri = encodeURI(myUrl);
    let ft = new Transfer();
    var file = ft.download(uri, location);

Use this code.