【问题标题】:Jszip and jszip-utils Meteor - currupt image files when saving a zip fileJszip 和 jszip-utils Meteor - 保存 zip 文件时损坏的图像文件
【发布时间】:2018-08-14 02:46:25
【问题描述】:

您好,我正在尝试使用 JSZip 和 JSZip-utils 保存图像文件。

我可以打包文件,但是尝试在 windows 中查看时文件已损坏。

这是我的代码:

//returns a Jquery Promise (binary content for use in JSZip)
if (currentViewOption == "f"|| currentViewOption == "t") {
  const downloadPromise = new Promise(resolve => {
    JSZipUtils.getBinaryContent(frontImgUrl, (err, data) => resolve(data));
  });
  zip.file(frontImgID, downloadPromise);
}

if (currentViewOption == "b"||currentViewOption == "t") {
  const downloadPromise2 = new Promise(resolve => {
    JSZipUtils.getBinaryContent(backImgUrl, (err, data) => resolve(data));
  });          
  zip.file(backImgID, downloadPromise2);
}

var now = Helpers.prettifyDateTime(new Date());

//generation of the zip, and send to the users browser
zip.generateAsync({type:"blob", compression: "DEFLATE"})
  .then(function(content) {
    saveAs(content, "VPI Images_" + now + ".zip");
  }, function(err){
    console.log(err)
});

如果有人可以提供帮助,我将非常感激,我已经花了太长时间了。

提前致谢 - 马克

【问题讨论】:

    标签: meteor corrupt jszip


    【解决方案1】:

    我在将文件添加到 zip 时使用 blob:true 选项。

    zip.file("filename", data, {blob: true});
    

    在创建 zip 时,我没有使用压缩,我正在使用它。

    zip.generateAsync({type:"blob"}).then(function(content){
                        saveAs(content, "zipfilename");
                    });
    

    也许你需要在像这样使用 zip.file 时指定类型

    zip.file("filename", data, {blob:true, type:"img/png"})
    

    【讨论】:

      猜你喜欢
      • 2022-07-05
      • 2020-09-30
      • 2023-03-26
      • 1970-01-01
      • 2015-03-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 2019-12-12
      相关资源
      最近更新 更多