【问题标题】:Ionic 3 File Download using External Sharepoint File URL使用外部 Sharepoint 文件 URL 下载 Ionic 3 文件
【发布时间】:2018-11-18 11:04:32
【问题描述】:

我使用 Sharepoint 创建了 Ionic 项目,

我有一个存储在列表中的 pdf、xls、doc 等文件, 我有一个文件 URL 的实际路径, 我正在使用下载选项在我的应用程序中创建文档库, 当我单击下载图标时,我必须下载该特定文档。

我试过了

文件传输插件

我无法实现请帮我解决这个问题。

这里是我尝试过的代码。

文件传输方式:-

 this.download("sample","https://abcd.sharepoint.com/samplesite/Shared Documents/sample.pdf");

 download(fileName: string, filePath: any) {
        const url= encodeURI(filePath);
        const fileTransfer: FileTransferObject = this.transfer.create();      
        fileTransfer.download(url, this.file.externalRootDirectory + fileName, true).then((entry) => {
          //show toast message as success    
        }, (error) => {
          //show toast message as error        
        });
    }

请给出一些下载文件的想法。有没有其他方法可以在ionic3中使用url下载文件?

【问题讨论】:

  • 我自己终于得到了答案。工作pdf,excel文件下载成功。
  • 但是下载word文件时出现问题。它显示 allways 文件已损坏。我必须找到其他方法。

标签: angular sharepoint ionic3 spfx


【解决方案1】:
$ ionic cordova plugin add cordova-plugin-file-transfer
$ npm install --save @ionic-native/file-transfer

功能

const url = 'https://abcd.sharepoint.com/samplesite/Shared Documents/sample.pdf';
  fileTransfer.download(url, this.file.dataDirectory + 'sample.pdf').then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });

【讨论】:

  • 感谢您的快速回复。 this.file.dataDirectory 一旦我使用它这个路径我无法在我的手机中查看文件。
  • 否则,使用文件路径 this.file.externalRootDirectory 我找到该文件。但是一旦我打开它。它显示“文件似乎已损坏”弹出窗口出现
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-24
  • 2019-12-03
  • 2018-05-13
  • 1970-01-01
  • 2023-03-22
  • 2023-02-17
  • 1970-01-01
相关资源
最近更新 更多