Aller au contenu
uencoder

Comment en Trouver MIME Types

Look up MIME (content) types pour fichier extensions et vice versa.

问题

You besoin en définir le correct Content-Type en-tête pour un fichier ou determine quoi type un fichier est de its extension.

Prérequis

  • Understanding of HTTP headers
  • Knowledge of file types

Étapes

  1. 1. Look up by file extension

    Map the file extension to its MIME type: .json → application/json, .html → text/html, .png → image/png, .pdf → application/pdf. Use a comprehensive MIME type database for accurate mapping, as some extensions have multiple registered types.

    entrée
    .json
    输出
    application/json
  2. 2. Handle ambiguous extensions

    Some extensions map to multiple MIME types depending on context: .xml can be text/xml or application/xml, .js can be text/javascript or application/javascript. Use the most widely compatible type. For web serving, follow the IANA registry.

    entrée
    .xml
    输出
    application/xml (preferred)
  3. 3. Set the Content-Type correctly

    When serving files, set the Content-Type header to the correct MIME type. Browsers use this to determine how to handle the response. An incorrect type can cause a file to download instead of display, or render incorrectly. Add charset for text types: text/html; charset=utf-8.

    entrée
    serving a JSON file
    输出
    Content-Type: application/json; charset=utf-8

Résultat attendu

Le correct MIME type pour un fichier extension, ou le correct extension pour un MIME type.

Erreurs courantes

Wrong Content-Type causes file to download
Set the correct MIME type. For example, text/html for HTML, application/json for JSON. A wrong type like application/octet-stream causes download.
Missing charset for text types
Add charset=utf-8 to text MIME types (text/html, text/plain, application/json). Without it, the browser may guess the encoding incorrectly.

Dépannage指引

  • If a file renders as plain text, the Content-Type is likely text/plain instead of the correct type.
  • For custom file types, use application/octet-stream as a fallback.

Limites de sécurité

  • MIME type sniffing can be a security risk. Set X-Content-Type-Options: nosniff to prevent browsers from guessing the type.

Outils associés

参考链接