我正在尝试将刚刚在我的应用程序中注册的用户在 facebook 或 twitter 上的现有图像上传到 amazon s3,但是一些验证不允许我保存用户对象,抛出:Image is invalid.
我认为那是我的 extension_white_list但我删除了它,它一直在说Image is invalid.
- 这不是错误,我认为这只是来自carrierwave 验证的消息,即使图像url 字符串是正确的。
头像上传者
# 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
创建用户:
...
new_user = User.create( :name => auth['info']['name'],
:email => User.email_from_auth(auth) )
auth_image_url = Authentication.larger_image(auth) # a string of user image url from social network authentication data. ie: http://a0.twimg.com/profile_images/1255111511/skyline.jpg
unless auth_image_url.blank?
new_user.remote_image_url = auth_image_url
new_user.save
end
...