How can I make carrierwave not save the source file after version processing?

I use CarrierWave to upload files in Rails 3.1, and I'm looking for a way to save space on the server. Many of the uploaded photos exceed 20 MB, so after processing them up to 1024 x 1024, I would like to delete the original. Is there an easy way to do this in the bootloader class?

Thanks, --Mark

+7
source share
5 answers

You can define after_save callback in the model and delete the photo.

I don't know your model, but something like this might work if you configure 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 
+3
source

I had two versions and realized that I did not need the original

So instead

 version :thumb do process :resize_to_limit => [50, 50] end version :normal do process :resize_to_limit => [300,300] end 

I deleted: normal and added this

 process :resize_to_limit => [300, 300] 

Now the original is saved in the size that I need, and I do not have a third unused image on the server

+22
source

everything! The selected solution does not work for me. My decision:

  after :store, :remove_original_file def remove_original_file(p) if self.version_name.nil? self.file.delete if self.file.exists? end end 
+7
source
 class FileUploader < CarrierWave::Uploader::Base after :store, :delete_original_file def delete_original_file(new_file) File.delete path if version_name.blank? end include CarrierWave::RMagick storage :file . . # other configurations end 
+1
source

A little hack, but has a performance advantage

 my_uploader.send :store_versions!, open(my_file) 
0
source

All Articles