I'm developing a service that will receive a file through an HTTP Post request. The file is sent by the request body with a Content-Type: application/octet-stream
header. I want to limit the request body to 10MB. Here's a MRE of my goal:
@RestController
public class MyController {
@PostMapping("save")
public ResponseEntity<Map<String, Object>> save(@RequestBody byte[] data) {
return ResponseEntity.ok(Map.of("size", data.length));
}
}
To test my endpoint I tried this curl
command:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary "@my_big_binary_file.whatever" http://localhost:8080/save
I tried to set the following properties, but with no success:
server.tomcat.max-http-form-post-size=10MB
server.tomcat.max-swallow-size=10MB
So, my question is: I'm going have multiple requests like this on my service. How can I limit the size of all of them to 10MB? Also, and I think it's related: what's the purpose of these two properties? Isn't it what I was expecting?
Tested using Java 17 on Spring Boot 2.7.9 and 3.0.4
PS.: I know there's a way to limit multipart/form-data
requests using the properties below. That works just fine. But it's not what I need.
spring.servlet.multipart.max-file-size=10MB