The other day, I was trying to build a simple batch upload interface for a Java web application running Spring Boot with Spring MVC on Apache Tomcat. But when I tried reading the InputStream in my controller, it was always empty. Fortunately, this turned out to be quite easy to fix.

Spring MVC supports InputStream and Reader for accessing the request body, but it didn’t make a difference here, no matter which I used they were both empty. For larger amounts of data (more than 2 MB in my tests), the input was always complete, however.

It turns out that there’s a mechanism at work that consumes at least part of the body, but only if the Content-Type header is set to application/x-www-form-urlencoded, which is the default that browsers and tools like curl use.

The workaround is trivial – just use a different Content-Typeheader, which in my case is the proper solution anyway: