MIME type utilities for Elixir. Get the MIME type for an extension or a list of extensions for a MIME type. Documentation is available here.
Add the following to your mix.exs
file:
defp deps do
[{:mimex, "~> 0.1.0"}]
end
Then run mix deps.get
. You're now able to call the functions we provide. See
the section on functions for a brief reference.
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:
MIME.mime_type!/1
MIME.extension!/1
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 .
.