0

我创建了一个函数来下载共享点的多个文件的 zip 文件。

 function create_zip() {
    var zip = new JSZip();

    $.each(filePathArray, function (i, path) {

        var filename = path; //"file" + i +".txt";
        var filee = path.substring(path.lastIndexOf('/') + 1);

        var fileURL = appweburl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('" + filename + "')/$value?@target='" + hostweburl + "'";//$('#file').attr('href');
        var request = $.ajax({
            url: fileURL,
            type: "GET",
            contentType: "text/plain",

            mimeType: 'text/plain; charset=x-user-defined' // <-[1]
        });

        request.done(function (data) {
            //var filee = "MoveFiles" + count + ".txt";
            zip.file(filee, data, { binary: true }); // <- [2]
            //count++;
            vfilecount++;
            console.log(vfilecount);
            console.log(vfilecount);

            if (count == vfilecount) {
                zip.generateAsync({ type: "base64" }).then(function (data) {

                    location.href = "data:application/zip;base64," + data;

                });

            }

        });
    });
   }

现在此代码在 Chrome 和 mozilla 中可以正常工作,但在 IE 中不能正常工作。请提出任何方法。

4

1 回答 1

0

https://github.com/Stuk/jszip/issues/376所示(在此处重新发布以帮助他人):

  • mimeType: 'text/plain; charset=x-user-defined'在 IE 10 中不起作用。$.ajax用于下载文本内容,而不是二进制内容。与 XmlHttpRequest 相同,无需设置 responseType。浏览器将尝试从 UTF8 解码接收到的内容并破坏它(因为它是二进制内容,而不是文本)。使用 jQuery 插件(如jquery.binarytransport.js)或直接使用 xhr(with xhr.responseType = "blob")。
  • location.href = "data:application/zip;base64," + ...在 IE 中不起作用。而是生成一个 blob 并用于saveAs触发下载
于 2016-11-14T19:03:43.920 回答