通过 http 上传之前压缩文件
是否可以压缩从客户端浏览器发送到服务器的数据(文件上传)?
Flash、silverlight等技术都可以!
Is it possible to compress data being sent from the client's browser (a file upload) to the server?
Flash, silverlight and other technology is ok!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器从不压缩上传的数据,因为它们无法知道服务器是否支持它。
下载的内容可以被压缩,因为 Accept-Encoding 请求标头允许浏览器向服务器表明它支持压缩内容。不幸的是,没有等效的协议可以以另一种方式工作并允许服务器向浏览器指示它支持压缩。
如果您可以控制服务器和客户端(例如使用 silverlight、flash),那么您可以使用压缩的请求主体。
Browsers never compress uploaded data because they have no way of knowing whether the server supports it.
Downloaded content can be compressed because the Accept-Encoding request header allows the browser to indicate to the server that it supports compressed content. Unfortunately, there's no equivalent protocol that works the other way and allows the server to indicate to the browser that it supports compression.
If you have control over the server and client (e.g. using silverlight, flash) then you could make use of compressed request bodies.
对于 Silverlight,有一个名为 Xceed 的库,除其他外,它“允许您在上传数据时对其进行压缩。”,但它不是免费的。我相信这只能通过 Flash 或 Silverlight 等技术来完成,而不是在浏览器本身上完成。
我不同意上面关于浏览器自动执行此操作的海报,我相信这只发生在标准 HTML/CSS/文本文件中,并且仅当服务器和浏览器都启用了压缩(gzip、deflate)时。
For Silverlight there is a library called Xceed which amongst other things "Lets you compress data as it is being uploaded.", it is not free though. I believe that this can only be done via a technology such as Flash or Silverlight and not natively on the browser.
I disagree with the above poster about browsers doing this automatically and I believe this only happens with standard HTML/CSS/Text files and only if the server and browser both have compression enabled (gzip, deflate).