MIME

MIME type utilities for Elixir. Get the MIME type most commonly associated with an extension and vice-versa.

Functions

mimex provides the following functions:

  1. MIME.mime_type/1 — get the MIME type from the file extension.
  2. MIME.extension/1 — get the first extension for a MIME type.
  3. MIME.extensions/1 — get the list of extensions for a MIME type.

The above functions return {:ok, result} on success and {:error, reason} on error. We also provide throwing versions:

  1. MIME.mime_type!/1
  2. MIME.extension!/1
  3. MIME.extensions!/1

These either return the result on success or throw an ArgumentError with reason as the message on failure.

It doesn’t matter whether you call the above functions with upper or loewrcase extensions. It also doesn’t matter if the . is present or not. When you pass in a MIME type, we always return a lowercase extension with a ..

Summary

Functions

Get the first extension for mime_type

Throwing version of extension/1

Return a list of extensions associated with mime_type

Throwing version of extensions/1

Get the MIME type for extension

Thowing version of mime_type/1

Functions

extension(mime_type)

Get the first extension for mime_type.

On success, returns a tuple of the following format: {:ok, extension}. If no match is found, returns {:error, reason}.

extension!(mime_type)

Throwing version of extension/1.

extensions(mime_type)

Return a list of extensions associated with mime_type.

On success, returns a tuple of the following format: {:ok, [extensions]}. If no match is found, returns {:error, reason}.

extensions!(mime_type)

Throwing version of extensions/1

mime_type(extension)

Get the MIME type for extension.

Extensions can contain periods or UPPERCASE characters. We take care of the normalization. Returns {:ok, extension} on success, {:error, reason} on failure.

mime_type!(extension)

Thowing version of mime_type/1.