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 pro
everyone! Selected solution does not work for me. My solution:
after :store, :remove_original_file
def remove_original_file(p)
if self.version_name.nil?
self.file.delete if self.file.exists?
end
end
I used to have two versions and realized that I did not not need the original
So instead of having
version :thumb do
process :resize_to_limit => [50, 50]
end
version :normal do
process :resize_to_limit => [300,300]
end
I removed :normal and added this
process :resize_to_limit => [300, 300]
Now the original is saved in size I need and I don't have a third unused image on the server
It's a little bit hack but has performance advantage
my_uploader.send :store_versions!, open(my_file)
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
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