MIME Type Detector

Detect MIME types from file content or extensions.

MIME Type Detection

MIME types identify file formats - "text/html" for web pages, "application/json" for JSON, "image/png" for PNG images. Servers use these to tell browsers how to handle files.

This tool detects MIME types from file extensions or file contents. Useful when configuring web servers, debugging content-type issues, or identifying unknown files.

Common MIME Types

  • text/html: HTML documents
  • application/json: JSON data
  • image/jpeg: JPEG images
  • application/pdf: PDF documents

Understanding MIME Types

MIME (Multipurpose Internet Mail Extensions) types identify file formats on the internet. Originally designed for email attachments, they're now used throughout the web to tell browsers how to handle different content. A MIME type consists of a type and subtype separated by a slash, like "text/html" or "image/png".

The Content-Type header uses MIME types to tell browsers how to display content. Getting this wrong can cause security vulnerabilities or broken functionality'for example, serving JavaScript with "text/plain" prevents execution.

Frequently Asked Questions

Why might browser MIME and actual MIME differ?

Browsers often guess MIME types from file extensions, which can be wrong. Actual MIME detection reads the file's "magic bytes" (the first few bytes that identify the format). A .jpg file renamed to .png would show different browser vs. actual types.

Why is MIME type validation important for security?

Attackers can rename malicious files (like PHP scripts) with innocent extensions (like .jpg) to bypass upload filters. Actual MIME detection reveals the true file type regardless of extension, preventing this attack vector.

What is application/octet-stream?

This is the default MIME type for unknown binary files. It tells browsers to download rather than display the content. It's used when the specific file type can't be determined from the extension or file signature.

When You Actually Need This

File uploads need MIME type validation to ensure users aren't uploading dangerous file types. Your application accepts images, but someone uploads a file named image.jpg that's actually an executable. Checking the MIME type by reading the file's magic bytes — not just the extension — catches this. MIME detection is also crucial when building APIs that return files. If your endpoint serves PDFs, your Content-Type header must be application/pdf, and if you're dynamically generating or retrieving files from storage, detecting the MIME type programmatically ensures you set the correct header.

Debugging file upload issues is another common scenario. A user reports that uploading a PNG fails, but other PNGs work fine. Inspecting the file's MIME type reveals it's actually image/x-png (a legacy variant) instead of the standard image/png, and your backend validation only accepts the latter. Detecting MIME types before upload or in development clarifies whether the issue is with the file itself, the user's file-naming mistake, or your validation logic being too strict.