如何删除CarrierWave上传到S3的本地文件

时间:2017-07-21 13:49:41

标签: ruby-on-rails ruby amazon-s3 rubygems carrierwave

在使用CarrierWave gem将附件上传到Amazon S3的Rails 5中,如何在成功将图像上传到S3后让CarrierWave删除图像的本地副本?

1 个答案:

答案 0 :(得分:2)

如果您的/ tmp目录充满了机架tmp上传垃圾,您可以在回调中将其删除,如下所示:查看here

class FileUploader < CarrierWave::Uploader::Base
  after :store, :delete_old_tmp_file

  # remember the tmp file
  def cache!(new_file)
    super
    @old_tmp_file = new_file
  end

  def delete_old_tmp_file(dummy)
    @old_tmp_file.try :delete
  end
end