【问题标题】:Download not working using filetransfer plugin使用文件传输插件下载不起作用
【发布时间】:2018-03-22 20:57:22
【问题描述】:

我使用 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】:

    这看起来是正确的做法。

    我不确定您所说的“您看不到任何下载发生”是什么意思,但我假设您在文件系统中找不到该文件(否则请告诉我)。

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

    this.file.dataDirectory
    

    如果您将 this.file.dataDirectory 替换为 this.file.externalDataDirectory,您将在文件系统中找到该文档(类似于:file:///storage/emulated/0/Android/data/com.project。名称)。

    在这种情况下,离子原生文档不是那么好,请参阅 cordova 文件插件文档,其中列出了不同的可能性:

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

    【讨论】:

    • 嗨@JudgeFudge 我在 Cordova 文件传输中遇到了类似的问题。立即调用成功下载功能(没有进行中的调用!),当我浏览文件时它在那里但为空(0字节)。我正在下载的服务器有点慢(我从浏览器尝试过,下载时间比平时长)。我不知道该怎么办!
    猜你喜欢
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多