How to upload a big file from a form to Phoenix?

FYI, for the most up-to-date docs on this functionality (since this question and these answers are pretty out-of-date at this point), see the official docs at: https://phoenixframework.readme.io/docs/file-uploads


Note that the accepted answer means that all request types will increase their maximum allowed lengths. As of Feb 2022, the Plug.Parsers docs show that you can set this just for the multipart parser in your endpoint.ex as:

If you want to increase the limit only for multipart requests (which is typically the ones used for file uploads), you can do:

plug Plug.Parsers,
     parsers: [
       :url_encoded,
       {:multipart, length: 20_000_000}, # Increase to 20MB max upload
       :json
     ]

You can configure this in your config/config.exs file:

config :phoenix, MyApp.Router,
  ...
  parsers: [parsers: [:urlencoded, :multipart, :json],
            accept: ["*/*"],
            json_decoder: Poison,
            length: 100_000_000],