Elixir Libmagic Bindings

If you need to determine the type of a local file in Elixir, you can use Elixir libmagic bindings library. libmagic is the library that powers the file command.

man$  file

NAME
     file -- determine file type

See gen_magic in hex Build Status

For example, maybe you need to check what files are uploaded to your Phoenix application. Start the server under a supervisor or use a pool if you expect high throughput:

{:ok, _} = Supervisor.start_link([
  {GenMagic.ApprenticeServer,
  [name: :gen_magic]}],
  strategy: :one_for_one)

Inspect the uploaded file in your controller:

def upload(conn, %{"upload" => %{path: path}}) do
  {:ok, [mime_type: _, encoding: _, content: content]} = GenMagic.ApprenticeServer.file(:gen_magic, path)
  text(conn, "Received your file containing #{content}")
end