javascript 压缩文件(客户端)并上传

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24226889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:24:02  来源:igfitidea点击:

Compress files (client side) and upload

javascripthtmluploadzip

提问by Creature

What HTML5/Javascript method I can use to upload and compress files on the client side?

我可以使用什么 HTML5/Javascript 方法在客户端上传和压缩文件?

The code to select multiple files:

选择多个文件的代码:

Note: If you upload files occupying this method, the server is slow to compress files, to prevent overloading is preferable to compress from the client side

注意:如果上传占用此方法的文件,服务器压缩文件速度较慢,为防止过载最好从客户端压缩

 <form method="post" enctype="multipart/form-data"> 
    <input type="file" name="fileselect[]" multiple="multiple">
    <input type="submit">
 </form>

The code as I'd like it to be:

我希望的代码是:

<script>
 ...
</script> 
...
<form method="post" enctype="multipart/form-data"> 
    <input style="display:none" type="file" name="singlezipfile">
    <input type="submit">
 </form>

thanks in advance

提前致谢

回答by Bogdan Savluk

There is no built-in functionality to achieve this...

没有内置功能可以实现这一点......

But you can do this using FileReader API and javascript zip implementation like this one http://stuk.github.io/jszip/

但是你可以使用 FileReader API 和 javascript zip 实现来做到这一点http://stuk.github.io/jszip/