inspectDocument() from @file_router/sdk/inspect gives you a detailed picture of how FileRouter will classify a document before you send it to any provider. It runs entirely locally — it reads bytes from disk or memory and uses binary signature analysis to detect the real file type. No data is ever sent to a network endpoint during inspection.
Import
inspect-import.ts
How inspection works
When you pass a local file (aFile, Blob, path string, or bytes), inspectDocument() performs three checks:
- Extension MIME type — infers the MIME type from the filename extension (e.g.
.pdf→application/pdf). - Binary signature detection — reads the file’s magic bytes to identify the real format, independent of the filename.
- Mismatch detection — compares the resolved MIME type against the binary signature and sets
mismatch: trueif they conflict.
DocumentInspection
Whether the input was resolved as local bytes or as a URL.
The normalized filename resolved from the input (e.g.
'report.pdf'). For URLs, this is derived from the last path segment.The MIME type FileRouter will use when sending this document to a provider. Determined by applying the MIME resolution order: explicit MIME → extension →
application/octet-stream.The MIME type inferred from the filename extension alone. Absent when the extension is unrecognized or generic.
Present only for local files. Contains the MIME type and file extension identified from the file’s binary signature.
true when the resolvedMimeType is specific (not application/octet-stream) and conflicts with the binary signature detected in the file. A mismatch often means a file has been renamed or has the wrong extension.The byte size of the file. Present only for local file inputs, not for URLs.
Example: inspect a local PDF
inspect-pdf.ts
Example: inspect a URL
inspect-url.ts
Inspection is entirely optional. The FileRouter core router does not reject documents with unknown MIME types — text formats like CSV and Markdown do not have reliable binary signatures, and provider format support changes independently of FileRouter releases. Use
inspectDocument() when you want to validate inputs or debug unexpected provider behavior.