File handling guides

Look up a media type and compare the file header

·

A filename extension is a useful clue to a file format. For a saved file, media type lookup lets you compare that clue with bytes from the file header.

MIME Type Lookup

Find the PDF marker in a file named .png

Choose Check example file. The result for sample.png reads the .png extension and lists image/png. The header check instead finds application/pdf at byte offset 5, after the sample’s five-byte opening line.

The sample contains a PDF version marker to demonstrate how the two clues can differ. A full document reader can check the rest of a file. The lookup reads up to the first 4,096 bytes on your device.

WHATWG MIME Sniffing Standard signature patternsIANA Media Types registry

Find the preferred media type for a JavaScript file

Search for .js. Results include text/javascript and the historical application/javascript spelling. Choose the Text category and copy text/javascript for a contemporary JavaScript response.

The extension mappings come from a fixed mime-db snapshot. For registered naming, follow the IANA entry and the format’s specification. A search such as text/javascript; charset=utf-8 finds the base media type.

IANA Media Types registrymime-db 1.54.0 database and extension sourcesRFC 9239 ECMAScript Media Types

Distinguish a ZIP header from its contents

Open a .docx copy you already have. The extension points to a Word document, while a typical header match is application/zip. Both are consistent because the document package stores its parts inside a ZIP container.

For formats with a shared container or an unrecognized header, use the file’s source application to check the contents. See which candidate came from the filename and which came from the inspected bytes.

WHATWG MIME Sniffing Standard signature patternsmime-db 1.54.0 database and extension sources

Common questions

Why can one extension have several results?

Different format conventions can reuse an extension, and a historic MIME spelling may persist alongside a newer one. The list keeps the matches available in the snapshot.

What if the header result is empty?

Some formats lack a distinctive supported header, and a short or damaged file may omit it. Use the extension list and the file’s origin to decide what to check next.

Sources

Put it into practice.

Related guides