Search code examples
javaspring-bootapitomcatmultipartfile

MultipartException and IOFileUploadException when requests receives MultipartFile


I'm developing a spring API and I have an endpoint that receives a MultipartFile as parameter but in the production environment I'm receiving the following error in some cases:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.impl.IOFileUploadException: Processing of multipart/form-data request failed. java.io.EOFException

I'm using spring-boot-starter-tomcat:2.4.7 that uses tomcat:9.0.46

I'm having some difficulty to debug this error because it throws before the code starts so it never reaches the logs that I put.

Thank you. Regards.


Solution

  • If this does not happen all the time and only sometimes, its probably because the upload got interrupted ( browser got closed for example ). Therefore, there is nothing for you to change in the code.

    You can get more details if you enable Spring MVC debug logging

    application.properties

    logging.level.org.springframework.web: DEBUG
    

    Here's additional info about how you can efficiently log these kinds of errors.