question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tomcat does not create temporary directory used to store file uploads when it does not exist

See original GitHub issue

Steps 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.

full_log.txt

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:29 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
wilkinsonacommented, Jul 19, 2019

@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.

4reactions
wilkinsonacommented, Mar 7, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Tomcat to use a different temp directory for file ...
The java.io.tmpdir in Tomcat is set to $CATALINA_BASE/temp . You can change it by setting the $CATALINA_TMPDIR environment variable before ...
Read more >
Ask Question - Stack Overflow
The temporary upload location [/tmp/tomcat.4296537502689403143.5000/work/Tomcat/localhost/ROOT] is not valid · I am not using File Upload things ...
Read more >
File Uploading in temp dorectory ot tomcat not in mentioned ...
Hi All, I am uploading a file into Thumbnail folder of real path like pathStr = request.getSession().getServletContext().getRealPath("/") + "Thumbnail/";
Read more >
Temporary upload location is not valid - Tridion Stack Exchange
Apparently the service creates a temporary Cataline base folder in /tmp, and uses that as its Tomcat home. The problem is now clear:...
Read more >
Confluence Home and other important directories
Removing plugins from this directory does not uninstall them. temp/. The temp directory is used for runtime functions such as exporting, importing, file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found