移动端实现附件下载


(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