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:
MIME.mime_type/1
— get the MIME type from the file extension.MIME.extension/1
— get the first extension for a MIME type.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:
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
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}
.
Throwing version of extension/1
.
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}
.
Throwing version of extensions/1
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.
Thowing version of mime_type/1
.