'HTTP4s increase max upload size
I am toying with http4s multipart file upload, which I got working. However, the multipart parsing throws an exception for file uploads bigger than ~500kb.
The error on client side, which is thrown while parsing multipart body is HTTP 422: The request body was invalid.
The error on the server side is "Part not terminated properly"
Since this is obviously related to the size of uploaded file, I suspect there must be a config in http4s to allow larger uploads?
Thanks in advance!
Solution 1:[1]
can you try changing content length in headers?
eg: content-length: 3495 OR Content-Length: 3495 depending on size of your content.
As I see this method getBody is called with len param
https://github.com/http4s/http4s/blob/4b928e0dc0ba6edbdbe7461204663e13a7013f8c/blaze-server/src/main/scala/org/http4s/blaze/server/Http2NodeStage.scala#L108
What I uncovered is that you can pass this header content-length to allow that size
ref for content length header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length
Hope it works.
Solution 2:[2]
There is a header to change the maximum size able to be uploaded called Content-Length.
This is the simple syntax:
Content-Length: <length>
The length parameter is just a number stating the number of bytes that is allowed for a maximum size.
Some examples include:
Content-Length: 6553
Content-Length: 54138
So, you can set the maximum size here.
To inspect this header in browsers, follow the steps below.
- Click Inspect Element in your browser.
- Click on the Network tab.
- Check the request header.
- Find the header
Content-Lengthin there.
If you want browser compatibility statistics, here they are:
- Google Chrome (and all Chromnium-based browsers)
- Firefox
- Opera
- Safari
- Microsoft Internet Explorer
This is how you can change the maximum file upload size with HTTP4.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | swapyonubuntu |
| Solution 2 |
