A modern REST API for file type detection powered by Google Magika - a deep learning model achieving >99% accuracy across 350+ file types.
- File Type Detection - Identify file types from binary content or URLs
- File Type Validation - Verify files match expected type(s)
- SSRF Protection - Secure URL fetching with comprehensive IP/hostname blocking
- OpenAPI Documentation - Interactive Swagger UI at
/docs
# Install dependencies
npm install
# Start the server
npm start
# Or run in development mode with watch
npm run devThe API will be available at http://localhost:3000
| Endpoint | Method | Description |
|---|---|---|
/detect |
POST | Detect file type from binary content |
/detect-url?url=<url> |
GET | Detect file type from a URL |
| Endpoint | Method | Description |
|---|---|---|
/validate?types=<types> |
POST | Validate binary content matches expected types |
/validate-url?url=<url>&types=<types> |
GET | Validate URL content matches expected types |
| Endpoint | Method | Description |
|---|---|---|
/types |
GET | List all supported file types |
/health |
GET | Health check |
/docs |
GET | Interactive API documentation |
curl -X POST http://localhost:3000/detect \
-H "Content-Type: application/octet-stream" \
--data-binary @image.pngResponse:
{
"type": "png",
"isText": false,
"confidence": 0.99,
"details": {
"dlPrediction": "png",
"overwriteReason": null
}
}curl "http://localhost:3000/detect-url?url=https://example.com/image.png"curl -X POST "http://localhost:3000/validate?types=png,jpeg,gif" \
-H "Content-Type: application/octet-stream" \
--data-binary @image.pngResponse:
{
"valid": true,
"detectedType": "png",
"expectedTypes": ["png", "jpeg", "gif"],
"confidence": 0.99
}curl http://localhost:3000/typesResponse:
{
"count": 353,
"types": [
{ "label": "png", "isText": false },
{ "label": "javascript", "isText": true }
]
}| Environment Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port |
HOST |
0.0.0.0 |
Server host |
- Fastify - High-performance web framework
- Magika - Google's deep learning file type detection
- Node.js >= 22.0.0 - Runtime environment
npm testMIT