我尝试从file input元素压缩一个文件,但它不起作用。我如何使用Javascript来做这件事?
var input = document.getElementById("id1");
const filereader = new FileReader();
filereader.onload = function() {
zip.file("picture.png", filereader.result, {binary: true});
}
filereader.readAsDataURL(input.files[0]);<input type="file" id="id1" style="border-radius: 0.1px; width: 40%;" accept="image/*">
发布于 2021-02-20 00:48:49
当zip.file(name, data [,options])接受blob数据类型时,您只需要获取它的文件
document.getElementById("id1").addEventListener("change", function (params) {
var zip = new JSZip();
var temp = this.files[0];
zip.file(temp.name, temp);
zip.generateAsync({ type: "blob" })
.then(function (content) {
// see FileSaver.js
saveAs(content, "example.zip");
});
})https://stackoverflow.com/questions/66280733
复制相似问题