如何通过一个 HTTP 请求下载多个文件? [英] How to download multiple files with one HTTP request?

查看:76
本文介绍了如何通过一个 HTTP 请求下载多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例:用户点击网页上的链接 - 砰!大量文件位于他的文件夹中.
我尝试使用 multipart/mixed message 打包文件,但它似乎只适用于 Firefox

Use case: user clicks the link on a webpage - boom! load of files sitting in his folder.
I tried to pack files using multipart/mixed message, but it seems to work only for Firefox

我的回答是这样的:

HTTP/1.0 200 OK
Connection: close
Date: Wed, 24 Jun 2009 23:41:40 GMT
Content-Type: multipart/mixed;boundary=AMZ90RFX875LKMFasdf09DDFF3
Client-Date: Wed, 24 Jun 2009 23:41:40 GMT
Client-Peer: 127.0.0.1:3000
Client-Response-Num: 1
MIME-Version: 1.0
Status: 200

--AMZ90RFX875LKMFasdf09DDFF3 
Content-type: image/jpeg 
Content-transfer-encoding: binary 
Content-disposition: attachment; filename="001.jpg" 

<< here goes binary data >>--AMZ90RFX875LKMFasdf09DDFF3 
Content-type: image/jpeg 
Content-transfer-encoding: binary 
Content-disposition: attachment; filename="002.jpg" 

<< here goes binary data >>--AMZ90RFX875LKMFasdf09DDFF3 
--AMZ90RFX875LKMFasdf09DDFF3--

谢谢

附言不,压缩文件不是一种选择

P.S. No, zipping files is not an option

推荐答案

压缩是唯一一个在所有浏览器上都能获得一致结果的选项.如果这不是一个选项,因为您不知道 zip 可以动态生成,那么它们可以.如果这不是一个选项,因为您对 zip 文件有怨恨,那么..

Zipping is the only option that will have consistent result on all browsers. If it's not an option because you don't know zips can be generated dynamically, well, they can. If it's not an option because you have a grudge against zip files, well..

MIME/multipart 用于电子邮件消息和/或 POST 传输到 HTTP 服务器.它从未打算在 HTTP 事务的客户端接收和解析.有些浏览器确实实现了它,有些则没有.

MIME/multipart is for email messages and/or POST transmission to the HTTP server. It was never intended to be received and parsed on the client side of a HTTP transaction. Some browsers do implement it, some others don't.

作为另一种选择,您可以使用 JavaScript 脚本打开下载各个文件的窗口.或者 Java Applet(需要机器上的 Java 运行时,如果它是企业应用程序,那应该不是问题[因为 NetAdmin 可以在工作站上部署它])将文件下载到用户选择的目录中.

As another alternative, you could have a JavaScript script opening windows downloading the individual files. Or a Java Applet (requires Java Runtimes on the machines, if it's an enterprise application, that shouldn't be a problem [as the NetAdmin can deploy it on the workstations]) that would download the files in a directory of the user's choice.

这篇关于如何通过一个 HTTP 请求下载多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆