Why are RackMultipart* files persisting in my Rails /tmp directory?

后端 未结 3 1234
一整个雨季
一整个雨季 2021-02-05 17:44

I\'m using Paperclip (2.3) to handle image uploads on a Rails 3.0.3 app running on Ubuntu. Paperclip is handling the uploads as advertised BUT the RackMultipart* files that are

相关标签:
3条回答
  • 2021-02-05 18:17

    I don't know if this is anymore elegant but this is what I am doing after the file is saved"

    tempfile = params[:file].tempfile.path
    if File::exists?(tempfile)
      File::delete(tempfile)
    end
    
    0 讨论(0)
  • 2021-02-05 18:18

    The TempFileReaper is the Rack middleware thought to handle this issue.

    http://www.rubydoc.info/github/rack/rack/Rack/TempfileReaper

    Including this line in the application.rb solves the problem:

    config.middleware.use Rack::TempfileReaper
    
    0 讨论(0)
  • 2021-02-05 18:23

    UPDATE: Problem should be resolved in rack-1.6.0.beta2. I see it's already being used in Rails 4.2.0.rc2.

    Below workaround served me well for almost a year:

    I've added this at the end of controller action that accepts file uploads:

    Thread.new { GC.start }
    

    This triggers Garbage Collection of unused Rack::Request objects which also deletes associated temp files. Note it doesn't sweep temp file of current request, but it does remove previous files, and prevents them from accumulating.

    0 讨论(0)
提交回复
热议问题