Simple upload file local Phoenix Elixir

There is a lack of information on how to do simple upload form in Phoenix Framework and store file into local storage. Although people recommend using Plug or external libraries, sometimes is useful to understand how essential thing work like upload image or PDF can be done using few Elixir scripts.

In this tutorial, I’m using an example of Hello project from Phoenix’s installation guideline. If you don’t have the project yet, please set-up by yourself since this tutorial does not cover it.

In the beginning, let write a path to access the upload page in the router, “lib/hello_web/router.ex”. Let use “upload” as the access path

  scope "/", HelloWeb do
    pipe_through :browser

    get "/", PageController, :index
    resources "/upload", UploadController, only: [:index, :create]