问题描述
作为标题,我可以这样做吗?将多个图像上传到浏览器,然后使用Javascript将其压缩为一个文件
请不要期待代码的答案,只是想知道这样做是可行的,有人可以给我一些提示或指导,谢谢。
解决方法
有一个js库可以解决您的问题。
这是链接http://stuk.github.io/jszip/
function upload(files){
var zip = new JSZip();
let archive = zip.folder("test");
files.map(function(file){
files.file(file.name,file.raw,{base64: true});
}.bind(this));
return archive.generateAsync({
type: "blob",compression: "DEFLATE",compressionOptions: {
level: 6
}
}).then(function(content){
// here you will get the zipped file,so you can pass this file to the server
});
}