title: Ruby on Rails: session-based temporary files? or not session?
body: <p>In my project I have file uploaded, validated and then user is asked for more input based on file content. The problem is that user can logout, lose internet connection, get hit by a bus, whatever... In the end orphaned file stays at server. Files are not that big to worry, but having a huge mess in tmp/ directory doesn't inspire me plus that opens a potential security risk (that is user doing a billion uploads and completely exhaust free space available to app).</p>
  
  <p>My current solution is own implementation of session storage based on ActiveRecord::SessionStore: ActiveRecord descendant with <code>after_destroy</code> hook removing orphaned files, add here a sidetiq worker that cleans timed out session and it'll be working ok.</p>
  
  <p>But this scenario has a big flaw: "remember me" that makes session permanent. Hence session is never destroyed (until user logs out manually) and files are not removed.</p>
  
  <p>My questions are:
  1. is there a better way to manage temporary files that are uploaded, but should be removed after processing / user logout / some timeout / ...?
  2. is there a gem helping with that? I have my solution, but I'm not exactly sure it is implemented correctly.</p>