Detect file type from content bytes using magic number analysis
Identify file types from their content bytes using magic number analysis, independent of file extensions or user-declared MIME types. File type detection prevents extension spoofing attacks, validates uploads before processing, and ensures your application handles files safely — critical for any platform that accepts user-uploaded content.
X-API-Key header with every request.
All requests go through the API gateway which handles authentication, rate limiting, and usage tracking.
{
"file": "(base64-encoded file content)",
"filename": "document.pdf"
}
| Field | Type | Description |
|---|---|---|
file |
string |
Field value |
filename |
string |
Field value |
{
"detected": true,
"mimeType": "application/pdf",
"extension": "pdf",
"category": "document",
"magicBytes": "25504446",
"confidence": 1.0
}
| Field | Type | Description |
|---|---|---|
detected |
boolean |
Field value |
mimeType |
string |
Field value |
extension |
string |
Field value |
category |
string |
Field value |
magicBytes |
string |
Field value |
confidence |
number |
Field value |
| Status | Meaning |
|---|---|
200 | Request completed successfully |
400 | Bad request — invalid or missing parameters |
401 | Missing or invalid X-API-Key header |
429 | Rate limit exceeded — check Retry-After header |
500 | Internal server error |
400 Empty fileRequest that triggers this:
(empty file upload)
Error response:
{"type": "/problems/validation-error", "title": "Empty File", "status": 400, "detail": "File cannot be empty"}
How to fix: Upload a file with content. Ensure the file is not corrupted or zero-size.
413 File too largeRequest that triggers this:
(file > 50MB)
Error response:
{"type": "/problems/payload-too-large", "title": "File Too Large", "status": 413, "detail": "Maximum file size is 50MB"}
How to fix: Reduce file size or split into multiple files. Compress if applicable.
curl -X POST /v1/file/detect \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"file": "(base64-encoded file content)",
"filename": "document.pdf"
}'
// Node.js (18+) or modern browser
const response = await fetch("/v1/file/detect", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
"file": "(base64-encoded file content)",
"filename": "document.pdf"
}),
});
const data = await response.json();
console.log(response.status, data);
import requests
response = requests.post(
"/v1/file/detect",
headers={
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
json={
"file": "(base64-encoded file content)",
"filename": "document.pdf"
},
)
print(response.status_code)
print(response.json())
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader(`{
"file": "(base64-encoded file content)",
"filename": "document.pdf"
}`)
req, _ := http.NewRequest("POST", "/v1/file/detect", body)
req.Header.Set("X-API-Key", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(resp.StatusCode)
fmt.Println(string(data))
}
{
"name": "file_type",
"description": "Detect file type from content bytes using magic number analysis",
"inputSchema": {
"type": "object",
"properties": {
"api_key": {"type": "string", "description": "Your Orovai API key"},
"request": {"type": "object", "description": "Request body"}
},
"required": ["api_key", "request"]
},
"endpoint": "/v1/file/detect",
"method": "POST",
"headers": {
"X-API-Key": "{{api_key}}",
"Content-Type": "application/json"
}
}