我使用 IonicNative 插件来下载 pdf 文件。
https://ionicframework.com/docs/native/file-transfer/ https://ionicframework.com/docs/native/file-transfer/
我可以使用警报看到下载完成,但看不到任何下载发生。
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);
});
这是正确的方法还是我错过了一些东西?
这看起来是正确的方法。
我不确定“您看不到任何下载发生”是什么意思,但我假设您在文件系统中找不到该文件(否则请告诉我)。
在这种情况下,您将文件保存在私有数据存储中,指定为:
this.file.dataDirectory
如果将 this.file.dataDirectory 替换为 this.file.externalDataDirectory,您将在文件系统中找到该文档(类似于:file:///storage/emulated/0/Android/data/com.project.name)。
在这种情况下,离子本机文档不太好,请参阅 cordova 文件插件文档,其中列出了不同的可能性:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)