Overview
MIME type utilities provide file type detection based on file extensions and categorization of files by their content type.getMimeType()
Get the MIME type for a filename based on its extension.Signature
Parameters
- filename
string- File name or path
Returns
MIME type string. Returns'application/octet-stream' if extension is unknown.
Usage
getFileCategory()
Categorize a file by its MIME type.Signature
Parameters
- mime
string- MIME type string
Returns
Category:'text', 'image', 'video', 'audio', 'archive', or 'binary'
Usage
isBinaryMime()
Check if a MIME type represents binary (non-text) data.Signature
Parameters
- mime
string- MIME type string
Returns
true if the MIME type is binary (not text), false otherwise.
Usage
Supported File Types
Text Files
| Extension | MIME Type |
|---|---|
.txt | text/plain |
.md | text/markdown |
.json | application/json |
.js | text/javascript |
.ts | text/typescript |
.jsx | text/jsx |
.tsx | text/tsx |
.css | text/css |
.html | text/html |
.xml | text/xml |
.yaml, .yml | text/yaml |
.csv | text/csv |
.log | text/plain |
Programming Languages
| Extension | MIME Type |
|---|---|
.py | text/x-python |
.rb | text/x-ruby |
.go | text/x-go |
.rs | text/x-rust |
.c | text/x-c |
.cpp | text/x-c++ |
.java | text/x-java |
.sh, .bash, .zsh | text/x-shellscript |
.sql | text/x-sql |
Images
| Extension | MIME Type |
|---|---|
.png | image/png |
.jpg, .jpeg | image/jpeg |
.gif | image/gif |
.svg | image/svg+xml |
.webp | image/webp |
.ico | image/x-icon |
Video
| Extension | MIME Type |
|---|---|
.mp4 | video/mp4 |
.webm | video/webm |
.avi | video/x-msvideo |
.mov | video/quicktime |
.mkv | video/x-matroska |
Audio
| Extension | MIME Type |
|---|---|
.mp3 | audio/mpeg |
.wav | audio/wav |
.ogg | audio/ogg |
.flac | audio/flac |
.m4a | audio/mp4 |
Archives
| Extension | MIME Type |
|---|---|
.zip | application/zip |
.tar | application/x-tar |
.gz, .tgz | application/gzip |
.bz2 | application/x-bzip2 |
.7z | application/x-7z-compressed |
.rar | application/vnd.rar |
Binary / Application
| Extension | MIME Type |
|---|---|
.pdf | application/pdf |
.wasm | application/wasm |
.exe, .dll | application/x-msdownload |
.so, .dylib | application/x-sharedlib |
Usage Examples
File Upload Validation
Content Type Headers
File Processing by Type
Filter Files by Type
File Icon Selection
Directory Listing
Notes
- Detection is based on file extension only (not content analysis)
- Extensions are case-insensitive
- Unknown extensions return
'application/octet-stream' application/jsonis categorized as'text'- Path separators are allowed in filename