版本处理后,如何让载波不保存原始文件? [英] How can I make carrierwave not save the original file after versions are processed?
本文介绍了版本处理后,如何让载波不保存原始文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢,
--Mark
我不知道你的模型,但是像如果你定制它,这可能会工作:
class User<< ActiveRecord :: Base
after_create:convert_file
after_create:delete_original_file
def convert_file
#做你必须做的事情
end
def delete_original_file
File.delete self.original_file_path如果File.exists? self.original_file_path
end
end
I'm using CarrierWave for my file uploads in Rails 3.1, and I'm looking for a way to save server space. Many of the photos being uploaded are upwards of 20MB, so after processing them down to 1024 x 1024, I would like to remove the original. Is there any easy way to do that in the uploader class?
Thanks, --Mark
解决方案
You could define an after_save callback in you model and delete the photo..
I dont know your model but something like this may work if you customize it:
class User << ActiveRecord::Base
after_create :convert_file
after_create :delete_original_file
def convert_file
# do the things you have to do
end
def delete_original_file
File.delete self.original_file_path if File.exists? self.original_file_path
end
end
这篇关于版本处理后,如何让载波不保存原始文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文