如何使用JavaScript从zip文件中提取图像SRC,然后将其显示到网页
我有一个网页,其中删除提取文件的zip文件。如何获取文件并将其用作IMG SRC。我正在变得“未定义” imgurl1 价值
let url1 = "IM/" + DIALOG_BACKGROUND_IMAGE ;
try {
JSZip.loadAsync(newFile).then(function (zip) {
for (var name in zip.files) {
if (name === url1) {
return zipFiles.file(name).async('blob');
}
}
return zip.file("").async("string");
}).then(function success(blob) {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
imgurl1 = reader.result;
}
puttingData(data, imgurl1,imgurl1);
}, function error(e) {
console.log(e);
});
} catch (e) {
console.log(e);
}
I have a webpage where I drop the zip file which extracts the files. how to get the file and use it as img src. I'm getting 'undefined' imgurl1 value
let url1 = "IM/" + DIALOG_BACKGROUND_IMAGE ;
try {
JSZip.loadAsync(newFile).then(function (zip) {
for (var name in zip.files) {
if (name === url1) {
return zipFiles.file(name).async('blob');
}
}
return zip.file("").async("string");
}).then(function success(blob) {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
imgurl1 = reader.result;
}
puttingData(data, imgurl1,imgurl1);
}, function error(e) {
console.log(e);
});
} catch (e) {
console.log(e);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论