angular - ionic 3 - FileTransfer 无法下载文件

标签 angular ionic-framework ionic3

在 angular/ionic 应用程序中,我有以下代码可以从互联网下载 pdf。

public pdfDownload(){
        const fileTransfer: FileTransferObject = this.transfer.create();
        const mime = 'application/pdf';
        const pdfFile = 'http://www.pdf995.com/samples/pdf.pdf';
        // alert(this.file.dataDirectory);
        fileTransfer.download(pdfFile, this.file.dataDirectory + 'file.pdf', true)
            .then((entry) => {
                alert('download complete: ' + entry.toURL());
            }, (error) => {
                // handle error
            });
    }

但是现在我在我的 android 手机中寻找这个文件,但我找不到它。我手机里的路径是enter image description here 没有文件。我在哪里下载的?

最佳答案

在第二个参数中使用 this.file.externalDataDirectory+'file.pdf' 而不是 this.file.dataDirectory+'file.pdf'函数fileTransfer.download(1个参数,2个参数,3个参数);

例如

fileTransfer.download(pdfFile, this.file.externalDataDirectory + 'file.pdf', true)

关于angular - ionic 3 - FileTransfer 无法下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47561737/

相关文章:

android - 压缩对齐 : command not found

javascript - ng-toggle,添加到数组,

android - Ionic 3 Android 构建错误(找不到 support-v4.jar)

ionic-framework - Ionic 3 中无与伦比的深层链接

javascript - Angular - 调用另一个组件函数来切换 div 的显示

angular - ng-template 上不能有事件?嵌入式模板上的任何指令均未发出事件绑定(bind)单击

angular - 锤子 : enable vertical scroll with horizontal swipe

angular - typescript 参数类型不匹配不会抛出错误

node.js - 如何将模块(不在 npm 注册表中)安装到 ionic 项目?

javascript - ionic ionic 日期时间 : how to set default picker value