Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download not working using filetransfer plugin

I used IonicNative plugin for downloading pdf files.

https://ionicframework.com/docs/native/file-transfer/

I can see download complete using alert,but cannot see any download happening.

private filetransfer: FileTransferObject = this.transfer.create(); 
  const url = 'https://www.example.com/example%20test.pdf'; 
  this.filetransfer.download(url, this.file.dataDirectory + 'example%20test.pdf').then((entry) =>
          {
                  alert('download complete: ' + entry.toURL());
          },
 (error) => {
                  alert(error);
});

Is this the correct way to do or am I missing some thing?

like image 354
shalini Avatar asked Aug 12 '26 11:08

shalini


1 Answers

This looks like the correct way to do it.

I'm not quit sure what you mean with "you cannot see any download happening", but I'm assuming you can't find the file in the file system (otherwise just let me know).

In this case your saving the file in a private data storage, specified by:

this.file.dataDirectory

If you replace this.file.dataDirectory with this.file.externalDataDirectory, you will find the document in your file system (something like: file:///storage/emulated/0/Android/data/com.project.name).

The ionic native documentation is not that good in this case, see the cordova file plugin documentation instead, where the different possibilitiers are listed:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files.

like image 191
JudgeFudge Avatar answered Aug 15 '26 07:08

JudgeFudge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!