Thanks to visit codestin.com
Credit goes to hexdocs.pm

Plug v1.1.3 Plug.MIME

Maps MIME types to file extensions and vice versa.

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

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

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

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

Summary

Functions

Returns the extensions associated with a given MIME type

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

Returns the MIME type associated with a file extension. If no MIME type is known for file_extension, "application/octet-stream" is returned

Returns whether a MIME type is registered

Functions

extensions(type)

Specs

extensions(String.t) :: [String.t]

Returns the extensions associated with a given MIME type.

Examples

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

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

iex> Plug.MIME.extensions("foo/bar")
[]
path(path)

Specs

path(Path.t) :: String.t

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

Examples

iex> Plug.MIME.path("index.html")
"text/html"
type(file_extension)

Specs

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> Plug.MIME.type("txt")
"text/plain"

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

Specs

valid?(String.t) :: boolean

Returns whether a MIME type is registered.

Examples

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

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