移動端實現附件下載


(function(window) {
  /**
    下載文件
  @method app.download
  @static
  @param option {object}
  @param option.url {string} 下載的地址
  */
  app.download = function(option) {
    if (option && !option.attachmentUrl) {
      return;
    }
    var docuementName = option.attachmentName;
    var filePath = window.savePath + "/" + docuementName;
    console.log('下載處的filepath',filePath)
    var url = option.attachmentUrl;
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
      url,
      filePath,
      function(entry) {
        //將文件路徑保存起來,方便后面調用
        window.fileUri = entry.fullPath.replace("file:///", "file://");
        var URL = window.fileUri;
        app.openFile(URL, "", function(res) {
          app.hint("打開成功!");
        });
      },
      function(error) {
        console.log('打開失敗')
        app.hint("下載失敗!");
      }
    );
  };
})(window);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM