Ionic v4 download the image to download folder

this is not working properly…

downloadImage2(seletedImg) {

     //URL CONTAINTS IMAGE PATH

     const fileTransfer: FileTransferObject = this.transfer.create();

     var url = seletedImg.filepath;

     var filename = 'hello.jpg';

     alert(filename);

     var targetPath = this.file.externalRootDirectory + filename;

     var trustHosts = true

     var options = {};

   //  alert(cordova.file.externalRootDirectory);

     fileTransfer.download(url, targetPath,trustHosts, options)

       .then((result) =>{

        this.validation.presentToast("File Download Successfully");

       }, (error) => {

        this.validation.presentToast("File Not Download");

       });

}

I recommend using HttpClient and Capacitor’s filesystem capability here instead of the obsolete FileTransfer plugin.

1 Like