Download not working using filetransfer plugin

我是研究僧i 提交于 2019-12-12 16:27:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/46683889/download-not-working-using-filetransfer-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!