Managing Temp Files in Tomcat

Issue

  • How temp files in Tomcat are handled? Do they get deleted automatically after the file upload is successful?

Environment

  • Liferay DXP 7.4

Resolution

  • Temporary Files During Upload – Documents and Media:
    1. When files are uploaded via the Documents and Media portlet in Liferay, they are first placed into a temporary location, typically the tomcat/temp directory. This is a standard step in the upload process.
    2. During the upload, two temporary files are generated:
    • One with a unique identifier and no extension
    • Another prefixed with upload_ and containing the original file extension
    3. The Document and Media Library implements a method (deleteExpiredTemporaryFileEntries) and has a scheduled job for deleting temporary file entries.
    4. To view or adjust this behavior, you can navigate to:
    • Control Panel > Configuration > System Settings > Documents and Media > Service
    • Look for the setting: Temporary File Entries Check Interval
    • By default, it is set to 1, meaning the system will check every hour to remove expired temporary files (based on certain criteria).
    5. Therefore, under normal circumstances, these temporary files (related to Documents and Media) should be deleted automatically once the upload is complete or a preview for the same has been generated.
  • In Case Temp Files Persist:
    1. If you notice a large number of temp files accumulating, this could be due to:
    • Failed or interrupted uploads
    • Application server (Tomcat) limitations in handling temp files

    It's important to note that Liferay doesn't directly manage the tomcat/temp directory—this is handled by Tomcat itself.

  • Suggestions to Manage Temp Folder Growth:
  • Check Liferay logs: Look for any upload-related errors that might be preventing cleanup.
  • Scheduled cleanup: You may implement a regular cleanup process to remove stale files, but only after shutting down Tomcat. Deleting files while Tomcat is running can lead to instability or unexpected behavior.
  • Custom temp path: If needed, you can configure a custom temp directory to better isolate and manage these files. Refer to the official article: How do I change Tomcat's temp folder path to another?

 

この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています