Need to determine MIME types for file handling? This guide covers everything you need to know about looking up MIME types via API, including extension mapping, content types, and implementation examples.
What are MIME Types?
MIME (Multipurpose Internet Mail Extensions) types are standardized identifiers used to indicate the nature and format of a document or file. They're essential for proper file handling in web applications, email systems, and APIs.
A MIME type looks like: application/json or image/png
MIME Type Structure
MIME types consist of two parts separated by a slash:
- Type: The general category (text, image, audio, video, application)
- Subtype: The specific format (plain, html, png, mp4, json)
Examples: text/html, image/jpeg, application/pdf
Using the MIME Type API
TinyFn provides endpoints to look up MIME types:
GET https://api.tinyfn.io/v1/mime-type?extension=pdf
Headers: X-API-Key: your-api-key
{
"extension": "pdf",
"mime_type": "application/pdf",
"type": "application",
"subtype": "pdf",
"description": "Portable Document Format",
"compressible": false,
"charset": null
}
Parameters
| Parameter | Type | Description |
|---|---|---|
extension |
string | File extension (without dot) |
mime_type |
string | MIME type to look up extension for |
filename |
string | Full filename to extract MIME type |
Code Examples
JavaScript / Node.js
// Look up MIME type by extension
const response = await fetch(
'https://api.tinyfn.io/v1/mime-type?extension=json',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.mime_type); // "application/json"
// Look up extension by MIME type
const response2 = await fetch(
'https://api.tinyfn.io/v1/mime-type?mime_type=image/png',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data2 = await response2.json();
console.log(data2.extensions); // ["png"]
Python
import requests
# Get MIME type for file extension
response = requests.get(
'https://api.tinyfn.io/v1/mime-type',
params={'extension': 'mp4'},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"MIME type: {data['mime_type']}") # video/mp4
# Get MIME type from filename
response = requests.get(
'https://api.tinyfn.io/v1/mime-type',
params={'filename': 'document.pdf'},
headers={'X-API-Key': 'your-api-key'}
)
print(response.json()['mime_type']) # application/pdf
cURL
curl "https://api.tinyfn.io/v1/mime-type?extension=css" \
-H "X-API-Key: your-api-key"
Common MIME Types
| Extension | MIME Type | Description |
|---|---|---|
| .html | text/html | HTML document |
| .css | text/css | CSS stylesheet |
| .js | application/javascript | JavaScript |
| .json | application/json | JSON data |
| .png | image/png | PNG image |
| .jpg | image/jpeg | JPEG image |
| application/pdf | PDF document | |
| .mp4 | video/mp4 | MP4 video |
Best Practices
- Always set Content-Type: Include proper MIME types in HTTP responses
- Validate uploads: Check MIME types when accepting file uploads
- Don't trust extensions alone: File extensions can be spoofed
- Use standard types: Stick to registered MIME types when possible
Try the MIME Type API
Get your free API key and start looking up MIME types in seconds.
Get Free API Key