0

sharepoint用に複数ファイルの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。バイナリ コンテンツではなく、テキスト コンテンツをダウンロードするためのものです。responseType を設定しない XmlHttpRequest と同じです。ブラウザーは、受信したコンテンツを UTF8 からデコードして破損しようとします (テキストではなくバイナリ コンテンツであるため)。jQuery プラグイン ( jquery.binarytransport.jsなど) を使用するか、xhr を直接使用します ( を使用xhr.responseType = "blob")。
  • location.href = "data:application/zip;base64," + ...IEでは動作しません。代わりに blob を生成しsaveAs、ダウンロードのトリガーに使用します
于 2016-11-14T19:03:43.920 に答える