Increase request length in Phoenix to upload large files
I ran into an issue with Phoenix the other day when I tried to upload a file of a size of 9.5MB.
Plug.Parsers.RequestTooLargeError at POST /images the request is too large. If you are willing to process larger requests, please give a :length to Plug.Parsers
It turned out that the default supported request length is 8MB so I had to increase the size of it. Phoenix uses a Plug which is something similar to Rack in Rails – it’s an HTTP middleware, but with different architecture.
Plug has parsers and these parsers are responsible for handling the request and throw an error if request doesn’t fit validations. So we need to change the default configuration of parsers and to do that we need to modify
lib/endpoint.ex and add the following line.
plug Plug.Parsers, ... length: 100_000_000
Restart Phoenix and the big file is good to go.
Note that this is how you configure Phoenix 0.13.1. If you want to increase a request length in previous versions (from 0.5) you have to modify
config/config.ex and follow this advice.
Would you like to get top 5 links on Elixir every Monday?
Sign up to Elixir Digest and stay up to date!