javaspring-boottomcatcache-controlmultipartfile

Auto clean up tomcat cache - Multipart file temp uploads


I have Spring boot application that will allow user to upload multipart files and I will process those files. I have read in official documentation for multipart files.

The uploaded multipart file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired. The temporary storages will be cleared at the end of request processing.

The problem here is tomcat is running out of memory, where the deleted temp files remain in var/cache/tomcat8/work/catalina/localhost/ROOT folder.

enter image description here

When we restart apache or reboot the machine, those deleted files are removed. But how to clean up these files automatically from tomcat cache? Why its happening? Is there anyway to disable storing these temp multipart files uploads in the first place?


Solution

  • In the code, there was some input streams was not closed properly. After closing the streams in my code, the issue is resolved