Zum Inhalt springen
uencoder

Wie in Finden MIME Typen

Look up MIME (content) Typen für Datei extensions und vice versa.

问题

You brauchen in setzen der correct Content-Typ Header für ein Datei oder determine was Typ ein Datei ist von its extension.

Voraussetzungen

  • Understanding of HTTP headers
  • Knowledge of file types

Schritte

  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.

    Eingabe
    .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.

    Eingabe
    .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.

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

Erwartetes Ergebnis

Der correct MIME Typ für ein Datei extension, oder der correct extension für ein MIME Typ.

Häufige Fehler

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.

Troubleshooting指引

  • 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.

Sicherheitsgrenzen

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

Verwandte Tools

参考链接