Validates file content against claimed MIME types using magic bytes.
Prevents file type spoofing by checking actual file signatures instead of relying solely on file extensions or Content-Type headers.
Summary
Functions
Validates that file content matches the claimed MIME type.
Types
@type validation_result() :: :ok | {:error, String.t()}
Functions
@spec validate(binary(), String.t()) :: validation_result()
Validates that file content matches the claimed MIME type.
Uses magic bytes (file signatures) to verify the actual file format. Supported types: PDF, PNG, JPEG, JSON, CSV, TXT.
Examples
iex> pdf_data = "%PDF-1.4..."
iex> FileValidation.validate(pdf_data, "application/pdf")
:ok
iex> text_data = "not a pdf"
iex> FileValidation.validate(text_data, "application/pdf")
{:error, "File content does not match type application/pdf"}