Search code examples
file-uploadelixirphoenix-framework

How do you use the plug.parser to accept larger files


I'm trying to upload a file, and I keep getting the file size is too large.

Plug.Parsers.RequestTooLargeError at POST /admin/courses/course the request is too large. If you are willing to process larger requests, please give a :length to Plug.Parsers

I'm new to elixir and pheonix. Is this not how I am supposed to set the plug?

defmodule MonolithWeb.Router do
  use MonolithWeb, :router
  use Kaffy.Routes, scope: "/admin", pipe_through: [:admin, :authenticate]

  pipeline :admin do
    plug Plug.Parsers,
     parsers: [:url_encoded, :multipart],
     length: 200_000_000_000
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
    plug :fetch_current_user
  end

Any help would be very much appreciated. Thank you!


Solution

  • In Phoenix, the Plug.Parsers plug is placed in the Endpoint by default, so that is probably where you need to add the length option.