Attached.Originals.ContentType (Attached v0.1.0)

Copy Markdown View Source

Detects the real content type of a file by reading its magic bytes.

Used by Attached.Originals during ingest to override the caller-supplied content type with the actual file type. Falls back to the supplied value when the magic bytes are unrecognized.

Configuration

# Disable automatic detection (not recommended):
config :attached, identify_content_type: false

Summary

Functions

Reads up to 16 bytes from path and returns the detected MIME type, or fallback if the file cannot be read or the type is unrecognized.

Functions

detect(path, fallback \\ "application/octet-stream")

Reads up to 16 bytes from path and returns the detected MIME type, or fallback if the file cannot be read or the type is unrecognized.

Returns fallback without reading when config :attached, identify_content_type: false is set.