您好,我正在尝试使用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)
});如果有人能帮助我,我将非常感激,我已经在这上面花了太长时间了。
提前感谢- Mark
发布于 2018-10-10 21:09:08
我正在使用blob:true选项,同时添加一个文件到zip。
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"})https://stackoverflow.com/questions/49127525
复制相似问题