What is the Content-Disposition header?
The Content-Disposition response header tells the client how to present the body: rendered inline within the browser, or as an attachment that prompts a download. When set to attachment, it can also suggest a filename.
API Usage & Best Practices
- Trigger downloads: Use
attachment; filename="report.csv"when an API endpoint returns a file the user should save rather than view. - Display inline: Use
inlinefor previewable content such as PDFs or images meant to render directly. - Encode non-ASCII names: Use the
filename*parameter with UTF-8 encoding (RFC 5987) for filenames containing non-ASCII characters.
Examples
HTTP/1.1 200 OKContent-Type: text/csvContent-Disposition: attachment; filename="export.csv"