File type detector API

Detect the real type of a file from its bytes (130+ formats), compare it with the name and Content-Type, and flag disguised executables and macros.

GETPOSThttps://apibox.io.vn/v1/file-type

Upload a file (multipart, raw body or file_base64) or give a url and the API identifies what the bytes really are, without trusting the extension: images (JPEG, PNG, WebP, AVIF, HEIC, raw photos…), PDF, Office documents (DOCX / XLSX / PPTX told apart by their ZIP entries, legacy DOC / XLS / PPT by their OLE2 streams, ODF, EPUB), archives (ZIP, RAR, 7z, gzip, bzip2, xz, zstd, tar, ISO…), audio and video containers, executables (Windows PE with architecture and DLL / .NET flags, ELF, Mach-O, APK, JAR, DEX, WebAssembly, scripts with a shebang, LNK shortcuts, MSI, DEB / RPM), fonts, SQLite and many data formats; text files are classified as SVG, HTML, XML, JSON, CSV, PEM and so on.

The answer gives the MIME type, canonical extension, kind and details, then compares it with the file name (filename, or the uploaded name) and the declared content_type. Warnings have a severity and the overall risk is the highest one: executables hidden behind a document or image extension, VBA macros (especially in a file named .docx / .xlsx), double extensions (invoice.pdf.exe), right-to-left override characters in names, SVG / HTML with scripts, PDF with JavaScript or Launch actions, archives containing executables.

Only the first 64 KB are inspected (plus the ZIP central directory for uploads), so a URL is fetched with a 64 KB cap. The file is not stored. This is a content-type check, not an antivirus: a "none" risk does not prove a file is harmless.

Parameters

NameInTypeRequiredDefault
filebodyfilenoThe file (multipart, raw body or file_base64).
urlquery|bodystringnoPublic URL of the file (first 64 KB are read).
filenamequery|bodystringnoFile name to compare with (default: uploaded name or URL path).
content_typequery|bodystringnoDeclared MIME type to compare with (default: upload / response Content-Type).

Example

curl -X POST "https://apibox.io.vn/v1/file-type" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "0=@./my-file"

Response

{
  "source": "upload",
  "file_name": "contract.docx",
  "size_bytes": 401,
  "bytes_inspected": 401,
  "type": {
    "extension": "docm",
    "mime": "application/vnd.ms-word.document.macroEnabled.12",
    "kind": "document",
    "description": "Word document with macros",
    "executable": false,
    "details": {
      "entries": 3,
      "entries_listed": "all",
      "macros": true
    }
  },
  "extension": "docx",
  "extension_matches": false,
  "declared_content_type": null,
  "content_type_matches": null,
  "expected_extensions": [
    "docm",
    "dotm"
  ],
  "risk": "high",
  "warnings": [
    {
      "code": "macros",
      "severity": "high",
      "message": "The file contains VBA macros but is named .docx (macro-free format)"
    },
    {
      "code": "extension_mismatch",
      "severity": "low",
      "message": "The name ends in .docx but the content is Word document with macros (.docm)"
    }
  ]
}

Use cases

  • Validate uploads before storing them (OWASP file upload checks)
  • Reject executables renamed as images or PDFs
  • Spot macro-enabled Office files sent by e-mail
  • Fix wrong Content-Type headers when serving user files

FAQ

How are DOCX, XLSX and PPTX distinguished?

They are all ZIP files: the API reads the entry names ([Content_Types].xml, word/, xl/, ppt/, vbaProject.bin) to tell them apart and to detect macros.

Does it scan for viruses?

No. It detects the real format and risky traits (executable code, macros, scripts); use an antivirus for malware.

How much of a URL is downloaded?

At most 64 KB. For ZIP-based files only the local headers in that part are read, which is enough to recognise Office files.

Related APIs

Start with 1,000 free requests every month. Get free API key →