Facebook / Twitter用户图像上传到S3时图像无效

时间:2012-12-05 19:32:11

标签: amazon-s3 ruby-on-rails-3.2 carrierwave image-uploading fog

我正在尝试从刚刚在我的应用程序中注册的用户上传到亚马逊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

1 个答案:

答案 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