2

每个人。尝试使用出色的 JSZIP 库将 mp3 添加到我的 zip 文件中,但未成功。现在,它只创建了具有正确文件名的 zip 文件,但 mp3 始终为空白。

这是我到目前为止的代码:

//init
var zip = new JSZip();

//add an mp3 titled "any other way" and decode binary to base64
zip.file("any other way.mp3", btoa("absolutepath/to/my/file/any_other_way.mp3"), {base64: true});

//generate zip
var content = zip.generate();

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

1 回答 1

1

所以,我最终在我的项目中包含了另一个带有 JSZIP 实用程序的 js 文件,并调用了以下方法,它在 Chrome 上下载得很好。但是,如果你想让它在 IE 和 safari 上运行,你必须实现 Downloadify ( http://stuk.github.io/jszip/documentation/howto/write_zip.html#toc_3 ):

  // loading a file and add it in a zip file
  JSZipUtils.getBinaryContent("path/to/audio.mp3", function (err, data) {
      if(err) {
      throw err; // or handle the error
      }
      var zip = new JSZip();
      zip.file("audio.mp3", data, {binary:true});
  });

http://stuk.github.io/jszip-utils/documentation/api/getbinarycontent.html

此外,这里是问题的链接:https ://github.com/Stuk/jszip/issues/176#issuecomment-57266207

于 2014-09-29T20:33:33.017 回答