Skip to content

MIME Detection

Accurate MIME type detection is crucial for handling media assets securely and efficiently.

The API relies on multiple strategies to determine the exact MIME type of a remote URL.

Resolution Strategy

  1. HTTP Headers: The primary source of truth is the Content-Type header returned by the remote server.
  2. File Extension Fallback: If the server returns a generic application/octet-stream or no content type at all, the URL is parsed for known media extensions (e.g., .mp4, .webp).
  3. Magic Byte Inspection (Future): Partial byte fetching to inspect file signatures when headers and extensions are unreliable.

Supported Classifications

The API normalizes detected MIME types into broad classifications to simplify downstream processing.

ClassificationExample MIME Types
imageimage/jpeg, image/png, image/webp, image/gif
videovideo/mp4, video/webm, video/ogg
audioaudio/mpeg, audio/wav, audio/ogg

Dealing with Inaccuracies

Many remote servers are misconfigured and return text/plain or application/octet-stream for valid media files. The API prioritizes the remote header but flags potential mismatches if the extension clearly contradicts the declared type.

Infrastructure Documentation — Behavior-Driven, Schema-Governed