使用jquerymobile在phonegap中下载多个文件

时间:2013-04-16 08:43:11

标签: android ios cordova mobile download

正如标题所说:有没有办法使用jquery mobile在phonegap中下载多个文件?

例如点击一个链接,并下载一个空洞存储库?

1 个答案:

答案 0 :(得分:0)

您可以使用手机间隙文件API文件传输对象

执行此操作

如果你想下载多个文件,那么你可以在循环中使用文件传输,或者如果下载文件是zip格式,那么你可以轻松地进行文件传输和extract zip plugin

方法1>

示例文件传输代码:

配置Zip插件然后应用此代码

function download(remoteFile)
{
      var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/') + 1);
          window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
              fileSystem.root.getFile(localFileName, { create: true, exclusive: false }, function (fileEntry) {
                  var localPath = fileEntry.fullPath;
                  console.log("localPath1:" + localPath);
                  if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
                      localPath = localPath.substring(7);
                  }
                  console.log("localPath2 save:" + localPath);
                console.log("thid is localFileName :"+localFileName);
                  extractFile(localFileName); //No need for other formated file except zip file.
                  var ft = new FileTransfer();
                  ft.download(remoteFile,
                      localPath, function (entry) {
                          console.log("file path:" + entry.fullPath);
                          var linkopen = document.getElementById("openlink");
                          linkopen.style.display = "block";
                          linkopen.href = entry.fullPath;
                          var zippath = entry.fullPath;
                          console.log(zippath);
                          $("#btnExtract").show();

                      }, fail);
              }, fail);
          }, fail);
       console.log("completed");
}

*这里编写此代码作为Zipfile的考虑因素。你需要改变代码。

方法2:删除

  

extractFile(localFileName);

来自代码