Tomcat does not create temporary directory used to store file uploads when it does not exist
See original GitHub issueSteps to Reproduce
When spring boot application starts with default value of server.tomcat.basedir
in application.properties
. It creates two folders in /tmp
folder. /tmp/tomcat.xxxxx/..
and /tmp-docbase.xxxx/
These directories are used to save temp files during multipart upload among other needed functions. In production system such as Centos, by default system is configured to delete all /tmp
files if not touched for 10 days. Once this file is deleted logs will show this error and upload will fail with following exception
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [**/tmp/tomcat.1220970741172837513.8080/work/Tomcat/localhost/ROOT]** is not valid
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:111)
Possible Solution: May be lets check if required temp directory doesn’t exist recreate during multipart upload. And upload will work without any additional settings. Other fixes/suggestions are welcome as well.
Affected Versions Logs are from Spring Boot v1.4.3.RELEASE but its still same in 1.5.3.RELEASE
Workarounds
- On Centos 7 update tmp.conf in following three directories /etc/tmpfiles.d/, /run/tmpfiles.d/ and /usr/lib/tmpfiles.d/. with following line x /tmp/tomcat*
OR handle programmatically
- Catch exception in
GlobalException
Handler and recreate directory and inform user to try upload again.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:29 (11 by maintainers)
@dixgaurav You can see the list of releases that contain the fix in the commit that closed this issue. In the 2.1.x line it was fixed in 2.1.4.
As of Tomcat 9.0.17 and 8.5.39, Tomcat will have opt-in support for creating the necessary directories when saving an upload. We can use this issue to opt in and update the documentation.