Content-Disposition Header Errors — File Download Naming and Handling Issues
About Content-Disposition Header Errors
Fix Content-Disposition header errors causing incorrect file names, failed downloads, and improper inline vs attachment handling in browsers. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: Content-Disposition controls whether the browser displays content inline or prompts a file download. The 'attachment' disposition triggers a download with the specified filename. The 'inline' disposition displays content in the browser (e.g., PDFs, images). Special characters and non-ASCII characters in filenames require RFC 5987 encoding. Different browsers handle Content-Disposition inconsistencies differently. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: Filename containing special characters (spaces, quotes, Unicode) not properly encoded. Missing Content-Disposition header causing browser to display binary content instead of downloading. Incorrect disposition type (inline when attachment was intended or vice versa). CDN or proxy stripping or modifying the Content-Disposition header. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Set the header correctly: Content-Disposition: attachment; filename="report.pdf"; filename*=UTF-8''report.pdf. Use RFC 5987 encoding for non-ASCII filenames: filename*=UTF-8''%E5%A0%B1%E5%91%8A.pdf. For inline display, use Content-Disposition: inline; filename="document.pdf" with appropriate Content-Type. Test across browsers — Chrome, Firefox, Safari, and Edge may handle edge cases differently. Ensure CDN pass-through: configure your CDN to not strip or cache Content-Disposition headers. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
What is the difference between inline and attachment?
Inline tells the browser to display the content directly (e.g., show a PDF in the browser). Attachment tells the browser to download the file and prompt a save dialog.
Overview
Fix Content-Disposition header errors causing incorrect file names, failed downloads, and improper inline vs attachment handling in browsers.
Key Details
- Content-Disposition controls whether the browser displays content inline or prompts a file download
- The 'attachment' disposition triggers a download with the specified filename
- The 'inline' disposition displays content in the browser (e.g., PDFs, images)
- Special characters and non-ASCII characters in filenames require RFC 5987 encoding
- Different browsers handle Content-Disposition inconsistencies differently
Common Causes
- Filename containing special characters (spaces, quotes, Unicode) not properly encoded
- Missing Content-Disposition header causing browser to display binary content instead of downloading
- Incorrect disposition type (inline when attachment was intended or vice versa)
- CDN or proxy stripping or modifying the Content-Disposition header
Steps
- 1Set the header correctly: Content-Disposition: attachment; filename="report.pdf"; filename*=UTF-8''report.pdf
- 2Use RFC 5987 encoding for non-ASCII filenames: filename*=UTF-8''%E5%A0%B1%E5%91%8A.pdf
- 3For inline display, use Content-Disposition: inline; filename="document.pdf" with appropriate Content-Type
- 4Test across browsers — Chrome, Firefox, Safari, and Edge may handle edge cases differently
- 5Ensure CDN pass-through: configure your CDN to not strip or cache Content-Disposition headers