Choosing the right MIME type, also called an HTTP Content-Type, helps browsers, APIs, storage services, and download clients handle files as intended. This practical reference explains how file extensions map to media types, when to use application/octet-stream, and how to check uploads, downloads, previews, and static assets before they reach production.
Overview
A MIME type describes the format of data being transferred. In HTTP, it is normally sent in the Content-Type response or request header. A value such as application/pdf tells a client that the body contains a PDF document, while image/png identifies a PNG image.
A file extension is only a naming convention. The extension .pdf commonly maps to application/pdf, but a renamed file is not automatically converted into a PDF. For uploads, treat the filename, declared MIME type, file signature, and actual parser result as separate pieces of information.
MIME types generally have a major type and a subtype, separated by a slash:
- text: human-readable text formats such as
text/plainandtext/css - image: still images such as
image/jpegandimage/svg+xml - audio and video: media streams and files
- application: structured data, documents, archives, fonts, and formats without a more specific top-level category
The most reliable choice is a specific, registered media type that matches the bytes being sent. application/octet-stream is a general binary fallback, not a universal replacement for every file type. It often causes a browser or download client to treat the response as an attachment or unknown binary data, which can be appropriate for downloads but unsuitable when the file should display in a preview.
Common MIME types by extension
Use this table as a working HTTP Content-Type reference. A server may add a character-set parameter to text responses, for example text/html; charset=UTF-8. The parameter describes how text is encoded; it does not change the underlying media type.
| Extension | MIME type | Typical use |
|---|---|---|
| .html, .htm | text/html | HTML pages |
| .css | text/css | Stylesheets |
| .js, .mjs | text/javascript | JavaScript modules and scripts |
| .json | application/json | JSON APIs and configuration data |
| .xml | application/xml | XML documents and feeds |
| .txt | text/plain | Plain text |
| .csv | text/csv | Comma-separated data |
application/pdf | Portable documents | |
| .doc | application/msword | Legacy Word documents |
| .docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document | Word documents |
| .xls | application/vnd.ms-excel | Legacy Excel workbooks |
| .xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | Excel workbooks |
| .pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation | PowerPoint presentations |
| .jpg, .jpeg | image/jpeg | JPEG images |
| .png | image/png | PNG images |
| .gif | image/gif | GIF images |
| .webp | image/webp | WebP images |
| .svg | image/svg+xml | Scalable vector graphics |
| .ico | image/x-icon | Common icon files |
| .mp3 | audio/mpeg | MP3 audio |
| .wav | audio/wav | Waveform audio |
| .ogg | audio/ogg | Ogg audio |
| .mp4 | video/mp4 | MP4 video |
| .webm | video/webm | WebM video |
| .zip | application/zip | ZIP archives |
| .gz | application/gzip | GZIP-compressed data |
| .tar | application/x-tar | TAR archives |
| .7z | application/x-7z-compressed | 7-Zip archives |
| .woff | font/woff | Web Open Font Format fonts |
| .woff2 | font/woff2 | Compressed web fonts |
| .ttf | font/ttf | TrueType fonts |
| .otf | font/otf | OpenType fonts |
| .wasm | application/wasm | WebAssembly modules |
Media-type registrations and platform conventions can change. For unusual or newly introduced formats, verify the current registration and the requirements of the client, framework, or storage provider rather than copying a similar-looking value.
Step-by-step workflow
- Identify the intended format. Start with the format produced by the application, not just the name supplied by the user. A file called
report.pdfshould contain a valid PDF structure before it is labeledapplication/pdf. - Choose the most specific media type. Prefer
application/jsonoverapplication/octet-streamfor JSON, andimage/pngover a generic binary value for a PNG. Specific types support better previews, validation, and client behavior. - Separate upload and download decisions. For an upload, inspect and validate the incoming object before storing or processing it. For a download, decide whether the client should preview it or save it, then set
Content-Typeand, when needed,Content-Dispositionaccordingly. - Check the full response. Inspect the status code,
Content-Type,Content-Disposition, caching headers, and response body. A correct MIME type cannot fix a truncated file, an HTML error page returned with a success status, or a response compressed incorrectly. - Test the real delivery path. Check local development, the application server, the reverse proxy, the object store, and the CDN separately. One layer may replace a header configured by another.
For API requests, the request body and response body can have different types. A client sending JSON commonly uses Content-Type: application/json, while the server should return the type of the response it actually generated. Do not confuse Content-Type with Accept: the former describes the body being sent, while the latter communicates response formats the client can handle.
Tools and handoffs
Browser developer tools are useful for confirming what reached the client. Open the Network panel, select the request, and inspect response headers and the preview or response body. Command-line tools can make the same check repeatable:
curl -I https://example.com/files/report.pdf
curl -v -o downloaded.pdf https://example.com/files/report.pdf
The first command requests headers when the server supports that method; the second shows the transfer details while saving the body. For a complete check, use a normal GET request as well, because some servers handle HEAD differently.
Server configuration should map extensions deliberately. In a static hosting setup, review the platform's MIME map and any custom metadata attached to stored objects. In an application, set the header close to the code that selects or generates the representation. Illustrative Node.js logic might look like this:
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'inline; filename="report.pdf"');
Use attachment instead of inline when the intended behavior is download, and construct filenames safely. For presigned URLs and object storage, confirm that the signing process preserves the desired response headers; see the guide to secure presigned file URLs for the surrounding workflow.
When a file fails to upload or download, review the related transfer and HTTP troubleshooting workflows. The file download headers guide covers disposition, ranges, and caching, while the upload validation guide covers checks that should happen before processing an uploaded object.
Quality checks
- Compare label and contents: Do not trust a client-supplied extension or MIME header as proof of file type. Use format-aware validation or signature checks appropriate to the application.
- Check preview behavior: Confirm that PDFs, images, audio, and video preview when intended, while sensitive or unsupported formats download instead.
- Check character encoding: For text, verify that the declared or selected charset matches the bytes. Test non-ASCII characters, line endings, and empty files.
- Check security boundaries: Avoid serving untrusted active content as if it were trusted application content. Uploaded HTML, scripts, and SVG files deserve particular review because their content may be interpreted by a browser.
- Check error responses: A missing file should not be returned with the MIME type of the requested asset. Confirm that error pages, redirects, and API errors have appropriate status codes and representations.
- Check caching and transformations: Image optimization, compression, antivirus scanning, and CDN transformations can alter the body or headers. Test the final response, not only the origin response.
- Check automation: Add representative files to integration tests, including a valid file, a mislabeled file, an empty file, and a corrupted or truncated file.
When the expected result is unclear, compare the file with a known-good sample of the same format. A file comparison or validation tool can help distinguish a header problem from a damaged payload; the file comparison workflow is useful for that investigation.
When to revisit
Keep this reference in your engineering documentation and revisit it whenever you add a file format, change a storage provider, introduce a CDN, modify static hosting, or upgrade a framework that manages media types. Also review it when a browser previews a file unexpectedly, a download opens as unreadable text, an API client rejects a response, or an upload passes extension checks but fails later processing.
For a practical maintenance routine, keep a small test matrix of the formats your product supports. After configuration changes, request each sample through its production-like path and record the final Content-Type, disposition, status code, content length, and preview or download behavior. Verify unusual formats against the current media-type registry and the documentation for the client or platform involved.
The next time you troubleshoot a file issue, follow this order: identify the actual bytes, select the most specific type, inspect the complete HTTP exchange, test every delivery layer, and then add the discovered case to an automated check. That process is more reliable than changing the extension or defaulting immediately to application/octet-stream.