Why Are Your Files Being Forced to Download?
The key combination of two HTTP response headers that triggers the “Save As” dialog in the browser:
1Content-Type (Content-Type)
This header acts like a “language translator” for files and must accurately match the file format. For example, if a PDF file is incorrectly labeled as text/plain, the browser will be confused and choose to download it. Here are some common values:
Document types:
application/pdf…
Image types:
image/jpeg, image/webp…
Multimedia:
video/mp4, audio/mpeg…
2Content-Disposition (Content-Disposition)
inline is the magic spell for opening previews, while attachment acts like a “do not open” seal on the file. A little secret: if this header is not set, the browser will guess whether to preview based on the file type!
Browser Compatibility
Not all formats can be “smoothly” opened; it depends on the browser you are using.
1Format Hierarchy
Images/PDFs/Videos: Most browsers can handle these without issues.
Office documents: May require external help like Microsoft 365.
Executable files: Always forced to download.
2Browser Quirks
Chrome may open PDFs smoothly, while Safari might stubbornly require a download; the same video file may auto-play in full screen on mobile but quietly sit on the page on desktop.
Advanced Tips Only Experts Know1Do Not Cross the Security Red Line
Displaying HTML/SVG files with inline? Beware of XSS attacks lurking! Just like you wouldn’t eat candy from a stranger, these file sources must be 100% reliable.
2Mobile’s Schrödinger Preview
The same PDF file may display directly on Android but redirect to the “Files” app on iOS. It’s like watching the same movie on different brands of TVs—the experience can vary greatly.
3Filename Fallback Strategy
Adding the filename=”report.pdf” parameter is like preparing a safety rope for the file. If the preview fails, at least the downloaded file name won’t appear as gibberish!
4Essential Debugging Toolkit
-
Open the browser developer tools (F12) and find the “culprit” response headers in the Network panel.
-
Use the mimetype detection tool to verify the file’s true identity.
Address: https://mimetype.io/
-
When testing on different devices, remember to “interrogate” Android and iOS separately.
Further Reading1For more details, see the following websites:
-
Content-Type Explanation
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type
-
Content-Disposition Explanation
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Disposition
-
Browser MIME Type Support List
https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types


OK, Done!