昨晚應用程序和db(mongodb)服務器都重新啓動。所有carrierwave安裝的上傳者都會返回頭像的默認圖像,即使這些文件仍然存在。重新啓動後載波重置
我在Rackspace CDN上使用霧氣存儲。每個用戶模型包含avatar_filename
的字段。我試過運行user.avatar.recreate_versions!
但是由於無錯誤而失敗。
有什麼方法可以恢復我的圖像(它們仍然存在!),並防止再次發生?我已經四處搜尋,但看起來這不是一個普通的舞會。
在我的用戶模型:
# 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
第一件事:把這個代碼在你上傳來解決這個問題:
您可以找到有關這個下面的wiki文章中的更多信息。爲什麼當模型有:avatar_filename字段的頭像存儲時,你在:avatar字段上調用mount_uploader? 第二步 - 您要在上傳器中定義文件名2次 - 在default_url和文件名方法中。無法理解你爲什麼需要這個,這也可能是問題的一部分。 – Almaron 2013-04-03 22:10:22
@Almaron由於安裝了上傳器,avatar_filename由carrierwave/carrierwave_mongoid創建。默認網址是爲尚未上傳的用戶提供空白頭像。 – 2013-04-04 19:02:31