我正在尝试从刚刚在我的应用程序中注册的用户上传到亚马逊s3上的Facebook或Twitter上的现有图像,但有些验证不允许我保存用户对象,抛出:{{1}我认为这是针对我的extension_white_list但我将其删除并继续说Image is invalid.
AvatarUploader
Image is invalid.
创建用户:
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
include CarrierWave::RMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
"avatar/#{model.id}"
end
version :thumb do
process resize_to_fill: [50, 50]
end
# def extension_white_list
# %w(jpg jpeg gif png bmp)
# end
end
答案 0 :(得分:2)
固定!该错误与carrierwave无关,只是在上传图像时数据库中不存在该对象的事实,首先我保存新用户然后:
after_create :upload_image_from_auth
def upload_image_from_auth
auth = self.authentications.first
unless auth.nil?
self.remote_image_url = auth.larger_image
self.save
end
end