0

I have the most basic spring-boot-starter web project with a single POST endpoint which prints the size of the request body

I want to configure spring boot so that it will not accept uploads of more than 32KB.

Is there anyway to achieve this?, i.e. to have spring boot mvc reject a request that exceeds the configured max upload size?

I am using spring boot version 2.1.5.RELEASE.

I have tried

server.tomcat.max-http-post-size=1KB
server.tomcat.max-swallow-size=1KB
spring.servlet.multipart.max-file-size=1KB
spring.servlet.multipart.max-request-size=1KB

This is my one and only endpoint:

    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResponseEntity<String> pong(@RequestBody String body) {
        return new ResponseEntity<>("FINISHED: " + body.length(), HttpStatus.OK);
    }

No matter which coniguration I use I can execute

curl -sS -X POST -H "Content-type: application/text" http://localhost:8080/ --data-binary @./file2.txt

where file2.txt is a 900Mb file and this results in

{"timestamp":"2019-06-18T17:52:03.244+0000","status":500,"error":"Internal Server Error","message":"Java heap space","path":"/"}

I would prefer some kind of exception that indicates this amount of data exceeds the configured limit.

Thank you.

  • https://stackoverflow.com/questions/33232849/increase-http-post-maxpostsize-in-spring-boot Does this help? – Matthew Kerian Jun 18 '19 at 18:13
  • Thanks, but the recommendations in here are to use the properties that I have already tried, none of these make a difference. I can always upload the massive file and get the Javaheap size error. Even with no properties it seems there is no default value - the upload can be attempted and the error results. – Daniel Chicot Jun 18 '19 at 18:45

0 Answers0