The purpose and usage of Content-Disposition in the header.
Content-Disposition is a field in the HTTP header that instructs the server on how to handle data attached to the message body. It can be used to control whether the browser downloads data as an attachment or displays it directly in the browser.
Here is how to use it:
- Add the Content-Disposition field in the HTTP response header, with the value of either inline or attachment. Inline means to directly display the data in the browser, while attachment means to download the data as a file.
- You can specify the filename for the downloaded file by setting the filename parameter, for example Content-Disposition: attachment; filename=”example.txt”.
- Parameters are used to specify the file name for downloading files and support non-ASCII character encoding, such as Content-Disposition: attachment; filename.
By using the Content-Disposition field, you can control the behavior of the browser to handle additional data in a specified way. For example, you can use Content-Disposition: attachment; filename=”example.txt” to force the browser to download the data named example.txt as an attachment.