使用filetransfer插件下载无法正常工作

问题描述 投票:0回答:1

我使用IonicNative插件下载pdf文件。

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);
});

这是正确的做法还是我错过了一些东西?

ionic-framework ionic-native
1个回答
0
投票

这看起来是正确的方法。

我不会放弃你的意思“你看不到任何下载发生”,但我假设你在文件系统中找不到该文件(否则只是让我知道)。

在这种情况下,您将文件保存在私有数据存储中,由以下内容指定:

this.file.dataDirectory

如果用this.file.externalDataDirectory替换this.file.dataDirectory,您将在文件系统中找到该文档(例如: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

© www.soinside.com 2019 - 2024. All rights reserved.