Carrierwave Reset after reboot

Both application servers and db (mongodb) were rebooted last night. All carrier-supported boot loaders return default images for avatars, although files still exist.

I use fog storage on a Rackspace CDN. Each user model contains an avatar_filename field. I tried to run user.avatar.recreate_versions! however, errors due to lack.

Is there a way to restore my images (they still exist!) And prevent this from happening again? I searched around, but it doesn't seem like this is a general release.

In my user model:

 # Avatar mount_uploader :avatar, AvatarUploader 

AvatarUploader:

 class AvatarUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick storage :fog def default_url "/assets/users/profile-default_#{version_name}.png" end # Large version :large do resize_to_limit(600, 600) end # Small version :small do process :crop resize_to_fill(140, 140) end # Thumbnail version :thumb, :from_version => :small do resize_to_fill(35, 35) end def extension_white_list %w(jpg jpeg png) end def filename if @filename_created @filename_created elsif original_filename @name ||= Digest::MD5.hexdigest(File.dirname(current_path)) @filename_created = "a_#{timestamp}_#{@name}.#{file.extension}" @filename_created end end def timestamp var = :"@#{mounted_as}_timestamp" model.instance_variable_get(var) or model.instance_variable_set(var, Time.now.to_i) end def crop if model.crop_x.present? resize_to_limit(600, 600) manipulate! do |img| x = model.crop_x.to_i y = model.crop_y.to_i w = model.crop_w.to_i h = model.crop_h.to_i img.crop!(x, y, w, h) end end end end 
+6
source share
1 answer

Given that there are images, you can reload them as deleted files using user.remote_avatar_url = "the url for this avatar"

To avoid this in the future, you need to keep in mind how you handle the file name. This process is reapplied every time you do recreate_versions! . Put this code in your bootloader to get around this:

 class AvatarUploader < CarrierWave::Uploader::Base def filename if original_filename if model && model.read_attribute(:avatar).present? model.read_attribute(:avatar) else # new filename end end end end 

Further information on this can be found in the following wiki article: https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Create-random-and-unique-filenames-for-all-versioned-files

+1
source

All Articles