Spring Boot: Failed to parse multipart servlet request; nested exception is java.io.IOException
Guys,
Here i am providing a quick resolution to the error thrown by container while uploading multipart content.
Error:
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.3966508010119674561.8080/work/<wbr />Tomcat/localhost/api] is not valid
Root Causes:
Spring will use temp
directory as a intermidiate location while doing multipart operation, container will create directory named tomcat.*
to store files temporaraly. As temp location will be used by mutple application OS will perform cleaning on unused objects that have not been used for some days (ideally 10 days).
Solution:
- Restart your container so it will pick a new location automatically if old one has been deleted. (Not a good idea :))
- Configure your custom temp location to handle mulitpart request using application properties. Example:
spring.servlet.multipart.location=YOUR_TEMP_LOCATION_PATH
orspring.http.multipart.location=YOUR_TEMP_LOCATION_PATH
(Choose appropriate property based on your boot version)
Happy leaning:)