兄弟,这叫 multipart !

兄弟,这叫 multipart !

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

如果只告诉你,我采用的 http 协议上传文件,你会怎样做?

可能会有多种方式,但至少我们得知道,http 协议的 GET 方法不靠谱,太短;

那么 POST 无疑是一个很适合的  Http 方法选择,因为它包体可以是无限长的内容。

至于是将文件内容进行BASE64编码之后放到包体中,还是使用 multipart/form-data 上传,这个看你喜欢。

以下是 html401 协议中的摘录,如需更详细的描述,可以参考 rfc1341 。

17.13.4 Form content types

The enctype attribute of the FORM element specifies the content type used to encode the form data set for submission to the server. User agents must support the content types listed below. Behavior for other content types is unspecified.

Please also consult the section on escaping ampersands in URI attribute values.

application/x-www-form-urlencoded  

This is the default content type. Forms submitted with this content type must be encoded as follows:

  1. Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
  2. The control names/values are listed in the order they appear in the document. The name is separated from the value by `=' and name/value pairs are separated from each other by `&'.

multipart/form-data  

Note. Please consult [RFC2388] for additional information about file uploads, including backwards compatibility issues, the relationship between "multipart/form-data" and other content types, performance issues, etc.

Please consult the appendix for information about security issues for forms.

The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.

The content "multipart/form-data" follows the rules of all multipart MIME data streams as outlined in [RFC2045]. The definition of "multipart/form-data" is available at the [IANA] registry.

A "multipart/form-data" message contains a series of parts, each representing a successful control. The parts are sent to the processing agent in the same order the corresponding controls appear in the document stream. Part boundaries should not occur in any of the data; how this is done lies outside the scope of this specification.

As with all multipart MIME types, each part has an optional "Content-Type" header that defaults to "text/plain". User agents should supply the "Content-Type" header, accompanied by a "charset" parameter.

Each part is expected to contain:

  1. a "Content-Disposition" header whose value is "form-data".
  2. a name attribute specifying the control name of the corresponding control. Control names originally encoded in non-ASCII character sets may be encoded using the method outlined in [RFC2045].

Thus, for example, for a control named "mycontrol", the corresponding part would be specified:

Content-Disposition: form-data; name="mycontrol"

As with all MIME transmissions, "CR LF" (i.e., `%0D%0A') is used to separate lines of data.

Each part may be encoded and the "Content-Transfer-Encoding" header supplied if the value of that part does not conform to the default (7BIT) encoding (see [RFC2045], section 6)

If the contents of a file are submitted with a form, the file input should be identified by the appropriate content type (e.g., "application/octet-stream"). If multiple files are to be returned as the result of a single form entry, they should be returned as "multipart/mixed" embedded within the "multipart/form-data".

The user agent should attempt to supply a file name for each submitted file. The file name may be specified with the "filename" parameter of the 'Content-Disposition: form-data' header, or, in the case of multiple files, in a 'Content-Disposition: file' header of the subpart. If the file name of the client's operating system is not in US-ASCII, the file name might be approximated or encoded using the method of [RFC2045]. This is convenient for those cases where, for example, the uploaded files might contain references to each other (e.g., a TeX file and its ".sty" auxiliary style description).

The following example illustrates "multipart/form-data" encoding. Suppose we have the following form:

 <FORM action="http://server.com/cgi/handle"
       enctype="multipart/form-data"
       method="post">
   <P>
   What is your name? <INPUT type="text" name="submit-name"><BR>
   What files are you sending? <INPUT type="file" name="files"><BR>
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>

If the user enters "Larry" in the text input, and selects the text file "file1.txt", the user agent might send back the following data:

   Content-Type: multipart/form-data; boundary=AaB03x

   --AaB03x
   Content-Disposition: form-data; name="submit-name"

   Larry
   --AaB03x
   Content-Disposition: form-data; name="files"; filename="file1.txt"
   Content-Type: text/plain

   ... contents of file1.txt ...
   --AaB03x--

If the user selected a second (image) file "file2.gif", the user agent might construct the parts as follows:

   Content-Type: multipart/form-data; boundary=AaB03x

   --AaB03x
   Content-Disposition: form-data; name="submit-name"

   Larry
   --AaB03x
   Content-Disposition: form-data; name="files"
   Content-Type: multipart/mixed; boundary=BbC04y

   --BbC04y
   Content-Disposition: file; filename="file1.txt"
   Content-Type: text/plain

   ... contents of file1.txt ...
   --BbC04y
   Content-Disposition: file; filename="file2.gif"
   Content-Type: image/gif
   Content-Transfer-Encoding: binary

   ...contents of file2.gif...
   --BbC04y--
   --AaB03x--
时间: 2024-08-03 13:41:33

兄弟,这叫 multipart !的相关文章

如何遍历一组file标签,如果其中某个的value值不为空,就将他的兄弟标签value置为空

问题描述 如何遍历一组file标签,如果其中某个的value值不为空,就将他的兄弟标签value置为空 <input type="hidden" name="updateImg" class="goods_image" value=""/> <input type="file" class="file_upload_tool goodsImage" name="

node.js的multipart模块问题

问题描述 node.js的multipart模块问题 multipart模块已经安装好了,node.js代码中有一行var parser=new multipart.parser()为什么运行后该行代码会报错:multipart.parser is not a function 解决方案 Node.js工具模块Node.js 模块和包Node.js fs 模块 解决方案二: https://cnodejs.org/topic/4ffed8544764b729026b1da3

Win10和他的老兄弟们

微软日前刚刚发布了最新版本的Windows操作系统,但微软为何跳过Windows9而直接发布Windows10引人遐思.即使Windows 10的发布充满了谜团,但其依然不失Windows不断进化的特性.除了特别版.家庭版以及专业版等外,Windows至少还有13个不同种类,有的甚至已经被人遗忘.在此,我们来看看Windows 10的几个老兄弟. Windows 1.0: 微软于1983年11月份正式发布,也就是苹果发布Mac OS前的3个月.但是这种Win1适用于图形用户界面(GUI),有点像

我要啦兄弟站长的传奇经历

站长 现在51la站长论坛和紫田网络在全国个人站长心中都很熟悉不过了.但是这才短短的三年,网络造就辉煌,成全所有努力和勤奋的人.    杨队,第一次看到他大队下载的域名,真感觉俗,俗不可耐,回到80年代农村时代了.那是04年,杨队的大队下载网站做的不错,宁愿说成seo技术不错,包括他的系列游戏类网站,无论在google还是在baidu,搜索很多下载和软件的都跑到他的网站.他的2个下载网站,也都有10来万的ip,在网站下面找到他的qq ,很快成了朋友,才逐渐认识这个有传奇色彩的站长.   这就是杨

E都市-兄弟帮在三维城市地图上奋斗

创业者的日子有多难?孙海涛的现身说法是:7个创业者通宵开头脑风暴会:断臂辞职,没有了后路:每个月收入800元:交通.电话没有报销:大热天穿着西服去找风险投资:办公在商住两用楼的小房间.    这就是三维地图网站E都市(www.edushi.com)成立之初的状态."这样的创意也不是一开始就有的",经历了创业第一步的孙海涛现在回想起当初的艰辛,还唏嘘不已.    跟孙海涛一起出来"闯"的还有他在杭州电子工学院的同学们,甚至还有同寝室的"战友".四年

将二进制字符转换成普通字符(multipart/form-data取出)

form-data|multipart|二进制|转换 <%response.expires=0'目的:将二进制字符转换成普通字符Function bin2str(binstr)Dim varlen,clow,ccc,skipflagskipflag=0ccc = ""varlen=LenB(binstr)For i=1 To varlenIf skipflag=0 Thenclow = MidB(binstr,i,1)If AscB(clow) > 127 Thenccc

自身经历告诫摸索中的兄弟,忘却SEO吧

混迹A5差不多有6,7年的时间了,每天都来查看各位大佬的经验心得,自己却总是潜水吸收,在此感谢各位大佬无私的分享,夜深人静,突然有了写作的冲动,只可惜自己文采太差,又是第一次发表,还望各位兄弟手下留情! 写这篇文章的目的,是因为自己的一个爱站排名出现很大下降,自己分析了很多原因,也算有所收获,在此分享一下,当然本文主要不是分享SEO的技术,其实SEO没什么技术可言,主要是分享下自己多年做SEO的一些心得体会,希望能给大家,特别是那些还在摸索中的兄弟带来一种心境的提升! 7年前开始建立自己的第一个

php HTTP请求类,支持GET,POST,Multipart/form-data

HttpRequest.class.php <?php /** HttpRequest class, HTTP请求类,支持GET,POST,Multipart/form-data * Date: 2013-09-25 * Author: fdipzone * Ver: 1.0 * * Func: * public setConfig 设置连接参数 * public setFormdata 设置表单数据 * public setFiledata 设置文件数据 * public send 发送数据

js如何获取兄弟、父类等节点

 本文为大家介绍下js获取兄弟.父类等节点的方法,感兴趣的朋友可以参考下 var chils= s.childNodes; //得到s的全部子节点    var par=s.parentNode; //得到s的父节点    var ns=s.nextSbiling; //获得s的下一个兄弟节点    var ps=s.previousSbiling; //得到s的上一个兄弟节点    var fc=s.firstChild; //获得s的第一个子节点    var lc=s.lastChile;