jq实现批量下载和打包下载

1.jq批量下载

function BatchDown(){
var mp3arr = ["http://localhost:48948/uploadfiles/0008/289a5a5d-c142-417d-9b40-0a7c8f707da2/attachmentEB519DA4D7A4C3DE556B4A01DA1008F70008.csv", "http://localhost:48948/uploadfiles/0008/289a5a5d-c142-417d-9b40-0a7c8f707da2/attachmentBCA72C7C7F10FF78AA0D9D6FEFC5A4D50008.xls", "http://localhost:48948/uploadfiles/0008/289a5a5d-c142-417d-9b40-0a7c8f707da2/attachment1893AE4D837B568079935B052BDE01DDC0008.xls"];

            for (var index = 0; index < mp3arr.length; index++) {
              download('第' + index + '个文件', mp3arr[index]);
           }

}

function download(name, href) {
       
        var a = document.createElement("a"), //创建a标签
        e = document.createEvent("MouseEvents"); //创建鼠标事件对象
        e.initEvent("click", false, false); //初始化事件对象
        a.href = href; //设置下载地址
        alert(href);
        a.download = name; //设置下载文件名
        a.dispatchEvent(e); //给指定的元素,执行事件click事件
    } 

但批量下载方式有时候会不好使,比如说在IE8浏览器上,IE8只支持同时下载一个附件,这时候就需要下面的方法,打包下载

 2.打包下载

 我用的开发语言的.net,用的打包插件是ICSharpCode

具体方法就不说了,以下代码主要是注意点的地方

 FileStream fs = System.IO.File.OpenRead(item.Key.ToString());
                        long dataLengthToRead = fs.Length;//获取下载的文件总大小
                        const long ChunkSize = 102400;//100K 每次读取文件,只读取100K,这样可以缓解服务器的压力
                        byte[] buffer = new byte[ChunkSize];
                        ZipEntry entry = new ZipEntry(yJK.FileOriginalName);
                        entry.DateTime = (DateTime)item.Value;
                        entry.Size = fs.Length;
                        zipoutputstream.PutNextEntry(entry);
                        while (dataLengthToRead > 0)
                        {
                            int lengthRead = fs.Read(buffer, 0, Convert.ToInt32(ChunkSize));//读取的大小
                            crc.Update(buffer, 0, lengthRead);
                            zipoutputstream.Write(buffer, 0, lengthRead);
                            dataLengthToRead = dataLengthToRead - lengthRead;
                        }
                        entry.Crc = crc.Value;
                        crc.Reset();
                        fs.Close();
原文地址:https://www.cnblogs.com/dushaojun/p/10314477.html