mime v1.3.1 MIME View Source

Maps MIME types to its file extensions and vice versa.

MIME types can be extended in your application configuration as follows:

config :mime, :types, %{
  "application/vnd.api+json" => ["json-api"]
}

After adding the configuration, MIME needs to be recompiled. If you are using mix, it can be done with:

$ mix deps.clean mime --build
$ mix deps.get

Link to this section Summary

Functions

Returns the custom types compiled into the MIME module

Returns the extensions associated with a given MIME type

Guesses the MIME type based on the path’s extension. See type/1

Returns whether an extension has a MIME type registered

Returns the MIME type associated with a file extension

Returns whether a MIME type is registered

Link to this section Functions

Returns the custom types compiled into the MIME module.

Link to this function extensions(type) View Source
extensions(String.t()) :: [String.t()]

Returns the extensions associated with a given MIME type.

Examples

iex> MIME.extensions("text/html")
["html", "htm"]

iex> MIME.extensions("application/json")
["json"]

iex> MIME.extensions("foo/bar")
[]
Link to this function from_path(path) View Source
from_path(Path.t()) :: String.t()

Guesses the MIME type based on the path’s extension. See type/1.

Examples

iex> MIME.from_path("index.html")
"text/html"
Link to this function has_type?(file_extension) View Source
has_type?(String.t()) :: boolean()

Returns whether an extension has a MIME type registered.

Examples

iex> MIME.has_type?("txt")
true

iex> MIME.has_type?("foobarbaz")
false
Link to this function type(file_extension) View Source
type(String.t()) :: String.t()

Returns the MIME type associated with a file extension.

If no MIME type is known for file_extension, "application/octet-stream" is returned.

Examples

iex> MIME.type("txt")
"text/plain"

iex> MIME.type("foobarbaz")
"application/octet-stream"

Returns whether a MIME type is registered.

Examples

iex> MIME.valid?("text/plain")
true

iex> MIME.valid?("foo/bar")
false