HTTP協議上傳boundary確定&下載content-disposition理解


HTTP協議上傳文件-協議

上傳文件需要將form標簽 的 ENCTYPE 屬性設置為 multipart/form-data屬性, 與

application/x-www-form-urlencoded類型不同, 此類型專門設計用來上傳文件, 而前者用來傳輸數據,

可以允許若干 控件域 同時上傳其值,

每個域值使用 boundary 分割:

 

     <FORM ACTION="http://server.dom/cgi/handle"
           ENCTYPE="multipart/form-data"
           METHOD=POST>
     What is your name? <INPUT TYPE=TEXT NAME=submitter>
     What files are you sending? <INPUT TYPE=FILE NAME=pics>
     </FORM>

 

   The client might send back the following data:

        Content-type: multipart/form-data, boundary=AaB03x

        --AaB03x
        content-disposition: form-data; name="field1"

        Joe Blow
        --AaB03x
        content-disposition: form-data; name="pics"; filename="file1.txt"
        Content-Type: text/plain

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

詳解見:

http://www.faqs.org/rfcs/rfc1867.html

 

HTTP協議上傳文件-boundary選取

 A
   boundary is selected that does not occur in any of the data. (This
   selection is sometimes done probabilisticly.) 

需要不能再文件中出現, 但實踐上不能掃描整個文件,再確定boundary, 所以往往是 生成一個隨機值。

具有一定的概率性, 隨着隨機值的長度變化, 所以沖突概率很低。

 

HTTP協議下載文件-協議

下載報文頭:

Content-Type: image/jpeg 

Content-Disposition: inline;filename=hello.jpg

Content-Description: just a small picture of me 

 

下載不要包括一個 頭域:

Content-Disposition 屬性是作為對下載文件的一個標識字段, 是對下載文件的顯示方式的描述。

腳本設置方法:

http://blog.csdn.net/androidmi/article/details/7519243

 

HTTP協議下載文件-content-disposition

content-disposition來自於 MIME (http://www.faqs.org/rfcs/rfc1521.html)

此協議僅僅規定報文傳輸過程, 但是並沒有規定,傳輸的內容對於接收端如何顯示處理。

[RFC 1521] specifies a standard format for encapsulating multiple
   pieces of data into a single Internet message. That document does not
   address the issue of presentation styles; it provides a framework for
   the interchange of message content, but leaves presentation issues
   solely in the hands of mail user agent (MUA) implementors.

 

http://www.rfc-editor.org/rfc/rfc1806.txt

此報文頭content-disposition, 對報文體進行描述, 規定了接收端的顯示處理行為。

此報文頭的值有兩種, attachment 和 inline, 分別表示保存 還是 直接顯示。

Two common ways of presenting multipart electronic messages are as a
   main document with a list of separate attachments, and as a single
   document with the various parts expanded (displayed) inline. The
   display of an attachment is generally construed to require positive
   action on the part of the recipient, while inline message components
 are displayed automatically when the message is viewed.

 

attachment and inline

        disposition := "Content-Disposition" ":"
                       disposition-type
                       *(";" disposition-parm)

        disposition-type := "inline"
                          / "attachment"
                          / extension-token
                          ; values are not case-sensitive

        disposition-parm := filename-parm / parameter

        filename-parm := "filename" "=" value;

 

disposition英文釋義

http://www.ldoceonline.com/dictionary/disposition

dis‧po‧si‧tion formal

1 [countable usually singular] a particular type of character which makes someone likely to behave or react in a certain way [= temperament]

of a nervous/sociable/sensitive etc disposition (=having a nervous etc character)

The film is not suitable for people of a nervous disposition.

have a cheerful/sunny etc disposition (=have a happy character)

2 [singular] a tendency or willingness to behave in a particular way [= inclination]

have/show a disposition to do something

Neither side shows the slightest disposition to compromise.

disposition towards

Most children have a disposition towards obedience.

3 [countable usually singular] the position or arrangement of something in a particular place

disposition of

a map showing the disposition of American forces

4 [uncountable] formal the way in which something is dealt with or used

disposition of

A solicitor advised him as to the disposition of the money.

5 [uncountable and countable] law the act of formally giving property to someone:

the disposition of assets on death

 

content-disposition 中 disposition 的含義是

4 [uncountable] formal the way in which something is dealt with or used

disposition of

 

即 content-disposition === the disposition of the message content 對消息內容的處理方式, inline 直接展示, attachment 以附件方式存儲。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM