您好我正在尝试使用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)
});
如果有人能提供帮助,我将非常感激,我已经花了太长时间。
先谢谢 - 马克
答案 0 :(得分:0)
我在将文件添加到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"})