javascript - jquery文件下载: download multiple files into chunks

标签 javascript jquery download

我正在使用 https://github.com/johnculviner/jquery.fileDownload下载一系列文件。似乎有效:

  for (var index = 0; index < files.length; ++index) {
    var file = files[index];
    $.fileDownload(file)
      .done(function() {
        alert("Done " + file);
      }
    )
      .fail(function() {
        alert("Fail " + file);
      }
    );
  }

如何一次下载 5 个文件的 block ? 文件正在下载,但暂时没有显示任何警报。所以我想我这里可能有问题。

例如,当尝试下载 100 个文件时,我想下载 5 个,然后再下载其他 5 个等,直到全部完成。这可能吗?

最佳答案

下载第一个文件

var firstfile = files[0]; //first file id
var downloadresult = downloadFileEx(firstfile);

然后用jquery then链接其他文件 并使用 array.slice挑选大块

var begin=1; // start from second file 
var end=5;

do {

for (var index = begin; index < files.slice(begin, end).length; i++) {
 var file = files[index];
(function (index) {
      downloadresult = downloadresult.then(function() {
        return downloadFileEx(array[index]);
       });
   }(index));
 }
index++;
 }
begin = begin +5; 
end = end + 5;
}
while (end  < files.length);

编写文件下载函数

function downloadFileEx(file) {
 return $.fileDownload(file)
      .done(function() {
        alert("Done " + file); // remove this 100 alerts will be blocked by browser, maintain an array of files
      }
    )
      .fail(function() {
        alert("Fail " + file);
      }
    );
}

关于javascript - jquery文件下载: download multiple files into chunks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42904445/

相关文章:

javascript - 下划线 _.object 但具有重复的处理函数,可能吗?

javascript - 类型检查和泛型

javascript - C - 使用 AES 加密和解密字符串

javascript - 单击按钮禁用特定的表单字段

javascript - css jquery Background fade to black upon clicking button...未知错误

file - YouTube获取视频文件链接

c# - 使用 CefSharp WinForms 下载文件

javascript - toString 或 to parseInt javascript

javascript - Jquery动态添加行不允许保存数据

用于下载项目的 C# 代码,检查文本/二进制和 gzip/非压缩?