MIME Types and File Extensions Reference
Understand MIME types, file extension mapping, and content type headers for proper file handling on the web.
Format Identifier
MIME Types and File Extensions
MIME types (Media Types) tell browsers and servers how to handle files. Incorrect MIME types cause downloads instead of rendering, security warnings, and broken functionality.
How MIME Types Work
A MIME type consists of a type and subtype: text/html, image/png, application/json. The type indicates the general category (text, image, audio, video, application). The subtype specifies the format. Servers send MIME types in the Content-Type HTTP header, and browsers use this (not the file extension) to determine how to handle the response.
Common MIME Type Mistakes
Serving JavaScript as text/javascript instead of application/javascript (though both work, the latter is the registered standard). Serving SVG as image/svg instead of image/svg+xml causes rendering failures. Missing charset for text types: text/html; charset=utf-8 is correct, text/html alone may default to Latin-1 in some browsers.
File Extension Mapping
Web servers map file extensions to MIME types via configuration (Apache's mime.types, Nginx's types block). If a new file type (.avif, .woff2, .webmanifest) isn't in the mapping, the server returns application/octet-stream, causing the browser to download rather than display the file. Update your server's MIME type configuration when deploying new file formats.
Security Implications
Browsers use MIME type sniffing to detect mismatches between the declared Content-Type and the actual file content. This can be exploited — an attacker uploads a file with an innocent extension but malicious content. The X-Content-Type-Options: nosniff header prevents MIME sniffing, forcing the browser to respect the declared Content-Type.
API and Download Handling
For file download endpoints, set Content-Disposition: attachment; filename="report.pdf" along with the correct Content-Type. For inline display, use Content-Disposition: inline. JSON APIs should always return application/json, not text/plain, to enable proper parsing and security protections in browsers.
Связанные инструменты
Связанные форматы
Связанные руководства
File Format Conversion: A Complete Guide
Converting files between formats is a daily task for professionals across every industry. This comprehensive guide covers document, image, audio, and video conversion principles that apply regardless of the specific tool.
CSV vs JSON vs XML: Data Exchange Formats Compared
Data exchange formats serve different needs. CSV excels at tabular data, JSON dominates web APIs, and XML powers enterprise integrations. This comparison helps you choose the right format for data interchange.
How to Convert Documents Between Office Formats
Converting between Word, Google Docs, LibreOffice, and PDF formats is common in collaborative workflows. This guide covers conversion paths that preserve formatting and identifies features that may be lost.
Understanding MIME Types and File Extensions
MIME types tell browsers and servers what kind of data a file contains, while file extensions help humans and operating systems identify file types. Mismatches between the two cause download and display problems.
Troubleshooting File Conversion Errors
File conversions fail for many reasons: corrupted sources, unsupported features, encoding mismatches, and memory limitations. This guide helps you diagnose and resolve the most common conversion failures.