Mobile-side implementation attachment downloads

(function(window) {
  /**
    download file
  @method app.download
  @static
  @param option {object}
  @param option.url {string} download address
  */
  app.download = function(option) {
    if (option && !option.attachmentUrl) {
      return;
    }
    var docuementName = option.attachmentName;
    var filePath = window.savePath + "/" + docuementName;
    console.log ( 'download at filepath', filePath)
    var url = option.attachmentUrl;
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
      url,
      filePath,
      function(entry) {
        // Save the file path together, easy to call back
        window.fileUri = entry.fullPath.replace("file:///", "file://");
        var URL = window.fileUri;
        app.openFile(URL, "", function(res) {
          app.hint ( "Open success!");
        });
      },
      function(error) {
        the console.log ( 'open failure ")
        app.hint ( "Download failed!");
      }
    );
  };
})(window);

Guess you like

Origin www.cnblogs.com/chchchc/p/12082285.html