昨晚重新启动了应用程序和数据库(mongodb)服务器。即使文件仍然存在,所有安装在载波上的上传器都将返回头像的默认图像。
我在 Rackspace CDN 上使用雾存储。每个用户模型都包含一个字段avatar_filename
。但是,我尝试运行user.avatar.recreate_versions!
由于 nil 而导致的错误。
有什么方法可以恢复我的图像(它们仍然存在!)并防止这种情况再次发生?我四处寻找,但看起来这不是一个普通的舞会。
在我的用户模型中:
# Avatar
mount_uploader :avatar, 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