0

After upgrading Spring Boot from 2.2.4 to 2.2.5 in my application, I get the following exception when uploading files with a multipart/form-data form:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly] with root cause

org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
    at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:1033)
    at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:931)
    at java.io.InputStream.read(InputStream.java:101)
    at org.apache.commons.fileupload.util.Streams.copy(Streams.java:98)
    at org.apache.commons.fileupload.util.Streams.copy(Streams.java:68)
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:346)
    at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:113)
    at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:159)
    at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:143)
    at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1178)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1012)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
...

The form looks like this:

<form id="addPhotosForm" method="post" action="/images/add" enctype="multipart/form-data">
    <div class="row">
        <div class="col-sm-4">
            <div class="input-group">
                <input type="file" name="images" multiple>
            </div>
        </div>
        <div class="col-sm-6 pull-left">
            <input name="submit" type="submit" value="Save">
        </div>
    </div>
</form>

And the controller looks like this:

@RequestMapping(value = "/images/add")
public String addPhoto(@RequestParam(value = "images", required = false) MultipartFile[] multipartImages) {
    //...
}
Vlad
  • 844
  • 1
  • 12
  • 22
  • My guess is that the problem is that the client is sending malformed requests, or maybe breaking the connection before the server has fully read it. But we can only guess. – Stephen C Mar 15 '20 at 04:45
  • 1
    I can confirm this is a Spring Boot Issue. We ran into the same problem after upgrading to Spring Boot 2.2.5. Downgrading fixed the issue. The client is definitely not cancelling the connection or sending invalid requests on my side. – kevcodez Mar 18 '20 at 10:04

1 Answers1

0

Works fine after updating Spring Boot to version 2.2.6.

Vlad
  • 844
  • 1
  • 12
  • 22