Content-Disposition
response header is a header indicating if the content is expected to be displayed inline in the browser, that is as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.In a multipart/form-data
body, the HTTP Content-Disposition
general header is a header that can be used on the subpart of a multipart body to give information about the field it applies to. The subpart is delimited by the boundary defined in the {{HTTPHeader("Content-Type")}} header. Used on the body itself, Content-Disposition
has no effect.
The Content-Disposition
header is defined in the larger context of MIME messages for e-mail, but only a subset of the possible parameters apply to HTTP forms and {{HTTPMethod("POST")}} requests. Only the value form-data
, as well as the optional parameter name
and filename
, can be used in the HTTP context.
Header type | {{Glossary("Response header")}} (for the main body) {{Glossary("General header")}} (for subpart of a multipart body) |
---|---|
{{Glossary("Forbidden header name")}} | no |
Syntax
As a response header for the main body
The first parameter in the HTTP context is either inline
(default value, indicating it can be display inside the Web page, or as the Web page) or attachment
(indicating it should be downloaded; most browsers presenting a 'Save as' dialog, prefilled with the value of the filename
parameters if present
Content-Disposition: inline Content-Disposition: attachement Content-Disposition: attachement; filename="filename.jpg"
As a header for a multipart body
The first parameter in the HTTP context is always form-data
; additional parameters are case-insensitive and have arguments, that use quoted-string syntax after the '='
sign. Multiple parameters are separated by a semi-colon (';'
).
Content-Disposition: form-data Content-Disposition: form-data; name="fieldName" Content-Disposition: form-data; name="fieldName"; filename="filename.jpg"
Parameters
name
- Is followed by a string containing the name of the HTML field in the form that the content of this subpart refer to. When dealing with multiple files in the same field (for example, the {{htmlattrxref("multiple", "input")}} attribute of an
{{HTMLElement("input","<input type=file>")}}
element, there can be several subparts with the same name.
Aname
with a value of'_charset_'
indicates that the part is not an HTML field, but the default charset to use for parts without explicit charset information. filename
- Is followed by a string containing the original name of the file transmitted. The filename is always optional and must not be used blindly by the application: path information should be striped, and conversion to the server file system rules should be done. This parameter provides mostly indicative information. When used in combination with
Content-Disposition: attachment
, it is used a the default filename for an eventual 'Save As" dialog presented to the user.
Examples
POST /test.html HTTP/1.1 Host: example.org Content-Type: multipart/form-data;boundary="boundary" --boundary Content-Disposition: form-data; name="field1" value1 --boundary Content-Disposition: form-data; name="field2"; filename="example.txt" value2
Specifications
Specification | Title |
---|---|
{{RFC("7578")}} | Returning Values from Forms: multipart/form-data |
{{RFC("2183")}} | Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field |
Browser compatibility
To contribute to this compatibility data, please write a pull request against this file: https://github.com/mdn/browser-compat-data/blob/master/http/headers.json.
{{Compat}}
See also
- HTML Forms
- The {{HTTPHeader("Content-Type")}} defining the boundary of the multipart body.
- The {{domxref("FormData")}} interface used to manipulate form data for use in the {{domxref("XMLHttpRequest")}} API.