Downloading files in Ionic using cordova-plugin-file-transfer

@pengzong I do not think it will work on a simulator - please try it on a device and post the error log.

Btw the first argument should be the image location, the second the target location. See here for example of which directory to save to: https://github.com/dsgriffin/ionic-2-file-transfer-example/blob/master/src/pages/home/home.ts

Thanks!It`s worked!My file location is wrong.

1 Like

This is my code;
downloadImage(image) {

this.platform.ready().then(() => {

  const fileTransfer = new Transfer();
  const imageLocation = `${cordova.file.applicationDirectory}www/assets/img/${image}`;
  // console.log(imageLocation,this.storageDirectory + image);
  fileTransfer.download(imageLocation, this.storageDirectory + image).then((entry) => {
    const alertSuccess = this.alertCtrl.create({
      title: `Download Succeeded!`,
      subTitle: `${image} was successfully downloaded to: ${entry.toNativeURL()}`,
      buttons: ['Ok']
    });

    alertSuccess.present();

  }, (error) => {

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

    alertFailure.present();

  });

});

}
I referred from git hub. it showing success message but file is missing in destination folder.
I think there is an error in download. plz help…

I have an requirement to cancel the download if i click cancel icon its possible to do that anyone help me.
I already started the download for 3 files if i want to cancel the second file download means how to do that help me
Thanks…

console.dir({"key": "value"})

I have a question to Your project. It saves file in then application folder but I would like to save it in Downloads folder. Im struggling with this a lot, I even got feeling that it is not possible to do it via Ionic. It seems I cannot access anything outside of the application folder. Would You like to tell me how to achieve that?

There are some examples on StackOverflow that should help:

Thank for the answer but i still could not resolve this issue. Particularly I have problem with using “window.requestFileSystem()”. I don’t inderstand how to use it, visual studio code shows that window has no method like this.
I described my problem here https://stackoverflow.com/questions/49444991/ionic-3-download-a-file-to-directory

Hi, I was able to download the file successfully in Ionic iOS. The file path after the successful download is like this.

file:///var/mobile/Containers/Data/Application/2F62D40C-2C61-4E4C-B51A-9B5217F4FD84/Documents/NF4016-130116.jpg

The above file is an image, but I’m not getting where this file is physically present on my iPhone 6s. I checked in photos app but it is not there. Any help would be appreciated.