How can I make carrierwave not save the original file after versions are processed?

前端 未结 5 1157
广开言路
广开言路 2020-12-16 04:17

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

5条回答
  •  無奈伤痛
    2020-12-16 04:48

    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
    

提交回复
热议问题