【发布时间】: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)
});
如果有人可以提供帮助,我将非常感激,我已经花了太长时间了。
提前致谢 - 马克
【问题讨论】: