MIME Types for File Upload Validation

File upload validation requires checking MIME type on both client and server. File.type limitations, magic byte detection, and validation in Multer, Django, and Spring Boot.

ZERO UPLOAD · ALL LOCAL
  1. Type a MIME string (e.g. application/json), file extension (e.g. .wasm), or keyword (e.g. "protobuf") to search the database.
  2. Use the category pills (Application, Audio, Font, Image, Model, Text, Video, Multipart) to browse all types in a category.
  3. Click Details on any card to expand the description, spec link, and server configuration snippets in a full-width panel.
  4. Click Copy next to any snippet block to copy the Nginx, Apache, .htaccess, or Caddy directive to your clipboard.

Magic byte signatures

  • JPEG FF D8 FF at byte offset 0
  • PNG 89 50 4E 47 0D 0A 1A 0A (8 bytes)
  • PDF ASCII %PDF — bytes 25 50 44 46
  • WebAssembly 00 61 73 6D — a null byte followed by ASCII "asm"

APPLICATION (100 types)

application/json
.json
application/xml
.xml .xsl .xslt
application/pdf
.pdf
application/wasm
.wasm
application/javascript
.js .mjs .cjs
application/zip
.zip
application/gzip
.gz .tgz
application/x-tar
.tar
application/x-7z-compressed
.7z
application/vnd.rar
.rar
application/x-bzip2
.bz2
application/vnd.openxmlformats-officedocument.wordprocessingml.document
.docx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xlsx
application/vnd.openxmlformats-officedocument.presentationml.presentation
.pptx
application/msword
.doc
application/vnd.ms-excel
.xls
application/vnd.ms-powerpoint
.ppt
application/octet-stream
.bin .exe .dll
application/x-www-form-urlencoded
application/cbor
.cbor
application/x-protobuf
.proto .pb
application/grpc
application/graphql-response+json
application/vnd.api+json
application/ld+json
.jsonld
application/hal+json
application/jwt
application/manifest+json
.webmanifest
application/rtf
.rtf
application/problem+json
application/json-patch+json
application/merge-patch+json
application/vnd.geo+json
.geojson
application/yaml
.yaml .yml
application/sql
.sql
application/epub+zip
.epub
application/java-archive
.jar
application/vnd.oasis.opendocument.text
.odt
application/vnd.oasis.opendocument.spreadsheet
.ods
application/vnd.oasis.opendocument.presentation
.odp
application/x-ndjson
.ndjson .jsonl
application/vnd.apple.mpegurl
.m3u8
application/dash+xml
.mpd
application/rss+xml
.rss
application/atom+xml
.atom
application/x-apple-diskimage
.dmg
application/x-debian-package
.deb
application/x-rpm
.rpm
application/x-sh
.sh
application/ecmascript
application/toml
.toml
application/zstd
.zst
application/x-xz
.xz
application/x-bzip
.bz
application/x-lzma
.lzma
application/x-iso9660-image
.iso
application/vnd.ms-cab-compressed
.cab
application/vnd.android.package-archive
.apk
application/x-msdownload
.msi
application/vnd.apple.installer+xml
.mpkg
application/x-httpd-cgi
.cgi
application/vnd.google-earth.kml+xml
.kml
application/vnd.google-earth.kmz
.kmz
application/vnd.sqlite3
.sqlite .sqlite3 .db
application/msgpack
.msgpack
application/schema+json
application/wsdl+xml
.wsdl
application/jose+json
application/x-pkcs12
.p12 .pfx
application/pkix-cert
.cer .der
application/x-pem-file
.pem .crt .key
application/pkcs8
.p8
application/pkcs10
.p10 .csr
application/postscript
.ps .eps .ai
application/x-latex
.latex .ltx
application/x-tex
.tex
application/x-dvi
.dvi
application/fits
.fits .fit .fts
application/vnd.oasis.opendocument.graphics
.odg
application/vnd.oasis.opendocument.chart
.odc
application/vnd.oasis.opendocument.formula
.odf
application/vnd.ms-project
.mpp .mpt
application/vnd.visio
.vsd .vst .vss .vsw
application/vnd.ms-access
.mdb
application/vnd.openxmlformats-officedocument.wordprocessingml.template
.dotx
application/vnd.ms-word.document.macroenabled.12
.docm
application/vnd.ms-excel.sheet.macroenabled.12
.xlsm
application/vnd.apple.pages
.pages
application/vnd.apple.numbers
.numbers
application/vnd.apple.keynote
.key
application/typescript
.ts
application/x-perl
.pl .pm
application/x-python-code
.pyc .pyo
application/x-csh
.csh
application/x-troff
.tr .roff .man
application/trig
.trig
application/n-triples
.nt
application/smil+xml
.smil .smi
application/vnd.mozilla.xul+xml
.xul
application/vnd.lotus-1-2-3
.123 .wks

AUDIO (23 types)

audio/mpeg
.mp3 .mpga
audio/ogg
.ogg .oga
audio/wav
.wav
audio/flac
.flac
audio/aac
.aac
audio/opus
.opus
audio/webm
.weba
audio/midi
.mid .midi
audio/mp4
.m4a .m4b .mp4a
audio/3gpp
.3gp .3gpp
audio/aiff
.aif .aiff
audio/x-ms-wma
.wma
audio/amr
.amr
audio/speex
.spx
audio/ac3
.ac3
audio/vorbis
audio/basic
.au .snd
audio/x-caf
.caf
audio/mpegurl
.m3u
audio/vnd.dts
.dts
audio/mp2
.mp2
audio/3gpp2
.3g2
audio/x-realaudio
.ra .ram

FONT (10 types)

font/woff
.woff
font/woff2
.woff2
font/ttf
.ttf
font/otf
.otf
application/vnd.ms-fontobject
.eot
font/collection
.ttc
font/sfnt
.sfnt
application/x-font-truetype
.ttf
application/x-font-opentype
.otf
application/x-font-woff
.woff

IMAGE (35 types)

image/jpeg
.jpg .jpeg .jfif
image/png
.png
image/gif
.gif
image/webp
.webp
image/avif
.avif
image/svg+xml
.svg .svgz
image/vnd.microsoft.icon
.ico
image/x-icon
.ico
image/bmp
.bmp
image/tiff
.tiff .tif
image/heic
.heic
image/heif
.heif
image/apng
.apng
image/jxl
.jxl
image/jp2
.jp2 .j2k .jpf
image/jpx
.jpx
image/vnd.djvu
.djvu .djv
image/vnd.adobe.photoshop
.psd
image/x-portable-bitmap
.pbm
image/x-portable-graymap
.pgm
image/x-portable-pixmap
.ppm
image/x-xcf
.xcf
image/ktx
.ktx
image/ktx2
.ktx2
image/x-exr
.exr
image/x-rgb
.rgb .rgba .sgi
image/x-xbitmap
.xbm
image/x-pcx
.pcx
image/vnd.wap.wbmp
.wbmp
image/x-tga
.tga .tpic
image/vnd.ms-photo
.jxr .hdp .wdp
image/x-win-bitmap
.cur
image/x-emf
.emf
image/wmf
.wmf
image/vnd.radiance
.hdr .rgbe

MODEL (19 types)

model/gltf+json
.gltf
model/gltf-binary
.glb
model/obj
.obj
model/stl
.stl
model/usd
.usd .usda .usdc
model/vnd.collada+xml
.dae
model/vnd.usdz+zip
.usdz
model/mtl
.mtl
model/vnd.dwf
.dwf
model/iges
.igs .iges
model/step
.stp .step .p21
model/step+xml
.stpx .stpxz
model/x3d+xml
.x3d
model/x3d+binary
.x3db .x3dbz
model/x3d-vrml
.x3dv .x3dvz
model/vnd.3mf
.3mf
model/vnd.fbx
.fbx
model/vnd.opengex
.ogex
model/JT
.jt

TEXT (33 types)

text/html
.html .htm
text/css
.css
text/csv
.csv
text/plain
.txt .text .conf .log
text/markdown
.md .markdown
text/calendar
.ics .ical .ifb
text/vcard
.vcf .vcard
text/javascript
.js
text/event-stream
text/tab-separated-values
.tsv
text/xml
.xml
text/x-python
.py .pyw
text/x-java-source
.java
text/x-c
.c .h
text/x-ruby
.rb
text/x-go
.go
text/x-rust
.rs
text/x-kotlin
.kt .kts
text/x-swift
.swift
text/x-scala
.scala .sc
text/x-php
.php .php3 .php4 .php5 .phtml
text/x-diff
.diff .patch
text/uri-list
.uri .urls .uris
text/x-rst
.rst
text/x-asciidoc
.adoc .asciidoc
text/x-nfo
.nfo
text/x-asm
.asm .s
text/troff
.roff .me .ms .mm
text/x-ini
.ini .cfg .inf
text/x-tcl
.tcl .tk
text/x-fortran
.f .f90 .for .f95
text/x-yaml
.yaml .yml
text/cache-manifest
.appcache .manifest

VIDEO (21 types)

video/mp4
.mp4 .m4v
video/webm
.webm
video/ogg
.ogv
video/x-msvideo
.avi
video/quicktime
.mov .qt
video/x-matroska
.mkv .mk3d
video/mp2t
.ts .mts .m2ts
video/mpeg
.mpeg .mpg
video/3gpp
.3gp .3gpp
video/3gpp2
.3g2 .3gp2
video/x-ms-wmv
.wmv
video/x-ms-asf
.asf .asx
video/vnd.avi
.avi
video/iso.segment
.m4s
video/x-dv
.dv .dif
video/x-ms-vob
.vob
video/H264
video/H265
video/AV1
video/x-flv
.flv
video/x-f4v
.f4v

MULTIPART (9 types)

multipart/form-data
multipart/byteranges
multipart/mixed
multipart/alternative
multipart/digest
multipart/related
multipart/signed
multipart/encrypted
multipart/report
No MIME types match your search.

MIME Types for File Upload Validation: Client-Side, Magic Bytes, and Frameworks

File upload validation requires checking MIME type on both client and server. Restricting file types to a safe allowed list prevents malicious uploads from reaching storage or being served to other users. The challenge is that MIME type information is available at two places in an upload flow, and neither is fully trustworthy alone.

On the client side, the browser's File API exposes file.type derived from the file extension, which an attacker trivially controls by renaming a file.1 On the server side, the Content-Type header in the multipart form-data body is also client-supplied and equally untrustworthy. Consequently, server-side validation must inspect the file's actual bytes, using magic number detection to identify the real format independent of the declared type. This magic byte approach is the only reliable way to verify file format on the server. Libraries like libmagic in Python and C, python-magic, and file-type in Node.js implement this detection.

Why client-side MIME type is not trustworthy

The File API's file.type property in the browser reads the MIME type from the operating system's file extension mapping, not from the file's actual content. Renaming a PHP script to image.jpg gives it file.type of "image/jpeg" according to the browser. The Content-Type header in the multipart form-data request body is set by the browser based on this same extension-derived value, meaning the server receives Content-Type: image/jpeg for the renamed PHP file. Both sources of MIME information are therefore client-controlled and cannot be trusted for security decisions.1

Client-side validation as a UX convenience only

Furthermore, client-side validation with accept attributes on file inputs and file.type checks in JavaScript is useful for user experience (preventing accidental wrong-format uploads) but provides no security value. All security-relevant type checking must happen server-side with content-based detection. The accept attribute on file inputs and JavaScript file.type checks are easily bypassed by renaming a file extension or crafting a request with spoofed headers, which means these client-side measures only protect against accidental mistakes by legitimate users, not against deliberate attacks.

Magic number checking and file signature verification

Every file format has characteristic byte sequences at known offsets in the file body, and these magic bytes (or file signatures) identify the actual format independent of the filename extension or declared MIME type that the client sent. JPEG files begin with FF D8 FF at byte offset 0, PNG files begin with the eight-byte sequence 89 50 4E 47 0D 0A 1A 0A, and PDF files start with the ASCII characters %PDF (bytes 25 50 44 46).2 WebP files have RIFF at offset 0 and WEBP at offset 8, while WebAssembly binaries begin with the null byte followed by the ASCII characters "asm" (00 61 73 6D). Checking these signatures on the server before storing or serving an uploaded file is the only reliable defence against type confusion attacks.

Libraries for server-side magic detection

python-magic is a Python binding to libmagic that detects format from bytes: magic.from_buffer(file_bytes, mime=True) returns the detected MIME type string.3 In Node.js, the file-type package reads the first bytes of a stream or buffer and returns the detected format without requiring the full file to be loaded into memory first. For Java, Apache Tika detects format from content and is the standard library for server-side type detection across enterprise applications.4 Using an allowed list that accepts only specific detected MIME types, rather than maintaining a blocklist of dangerous types, is the safer approach because it rejects any format you have not explicitly approved.

Framework-specific validation in Multer, Django, and Spring Boot

Framework-level upload validation provides a structured place to apply magic byte detection. In Node.js with Multer and Express, the fileFilter callback receives the file's mimetype from the Content-Type header and the req object; however, this mimetype is client-supplied.5 Pair the Multer fileFilter with post-upload magic detection using the file-type package on the stored bytes. In Python with Django, FILE_UPLOAD_VALIDATORS accepts a list of validator functions called after the upload is buffered.6 Apply magic byte detection inside a validator function using python-magic. In Spring Boot, @RequestParam MultipartFile exposes getContentType() which is client-supplied, so pair this with Apache Tika's Detector applied to the file's InputStream for server-side format verification.7 Consequently, framework-level hooks give you a clean integration point for magic detection without writing custom request parsing code.

Image reprocessing as a defence against polyglot file attacks

Magic byte detection identifies the file format from its leading bytes but cannot eliminate embedded payloads in the file body. A polyglot file starts with valid JPEG magic bytes and contains an HTML or script payload at a deeper byte offset, passing magic byte detection while embedding executable content. Re-encoding the uploaded image through an image library is a more robust defence: the encoder reads the file as image data and writes back only pixel values, discarding any non-image bytes in the process.

Sharp in Node.js reprocesses uploaded images with a single method chain: sharp(uploadedBuffer).jpeg({ quality: 85 }).toBuffer() reads the buffer as a JPEG and outputs clean, re-encoded bytes.8 An input buffer containing a payload rather than valid JPEG data causes Sharp to throw a decode error, which you catch and convert into a rejection response. The re-encoded output contains no trace of the original file's non-image content.

Protecting against pixel-flood inputs

Set a maximum input file size limit in your multipart parser before reprocessing begins, to prevent attackers from sending enormous image files that consume CPU. Additionally, Sharp's resize() method called before re-encoding limits the decoded pixel dimensions. A resize cap of 4000x4000 pixels prevents pixel-flood attacks where a specially crafted image claims to have extremely large dimensions that exhaust decoder memory. These two limits together constrain both bandwidth and CPU cost for the reprocessing step.

The limits should be set as part of the upload policy rather than buried in the reprocessing code, because a missing size cap before the image library runs still allows a malicious client to exhaust memory during decode. Placing the check at the parser boundary catches the oversized input before any expensive transformation begins. confirm upload Content-Type before storing so the stored object matches what the validator expects.

When to use this

Use this guide when implementing a file upload endpoint that needs to reject unwanted file types, auditing an existing upload endpoint for type-confusion vulnerabilities, or adding server-side MIME validation to a framework that relies on client-supplied Content-Type.

Examples

Node.js: magic byte detection with file-type after Multer upload

Multer stores the file first; then detect the actual format from the stored bytes using file-type before accepting the upload.

Python: magic byte detection with python-magic

Detect MIME type from file bytes server-side, independent of the client-supplied Content-Type header.

Never trust file.type alone in browser JavaScript

Before
// Insecure: file.type is extension-derived and attacker-controlled
if (file.type === 'image/jpeg') { upload(file); }
After
// Acceptable for UX only (add server-side magic detection)
if (file.type === 'image/jpeg') { upload(file); }
// Server validates actual bytes independently

Client-side type checks improve UX but provide zero security. Always validate on the server with magic byte detection.

Sources
  1. 1.

    Mozilla Developer Network, "File.type," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/API/File/type

  2. 2.

    W3C, "PNG Specification," w3.org, accessed June 2026. https://www.w3.org/TR/png/

  3. 3.

    "python-magic," PyPI, pypi.org, accessed June 2026. https://pypi.org/project/python-magic/

  4. 4.

    Apache Tika, "Detection," tika.apache.org, accessed June 2026. https://tika.apache.org/2.1.0/detection.html

  5. 5.

    "Multer," npm, npmjs.com, accessed June 2026. https://www.npmjs.com/package/multer

  6. 6.

    Django, "FILE_UPLOAD_VALIDATORS," docs.djangoproject.com, accessed June 2026. https://docs.djangoproject.com/en/stable/ref/settings/#file-upload-validators

  7. 7.

    Pivotal Software, "MultipartFile," Spring Framework docs.spring.io, accessed June 2026. https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html

  8. 8.

    "sharp," GitHub, github.com, accessed June 2026. https://github.com/lovell/sharp

FAQ