【问题标题】:Image invalid on facebook/twitter user image uploading to S3facebook/twitter 用户图像上传到 S3 上的图像无效
【发布时间】:2014-04-06 20:40:14
【问题描述】:

我正在尝试将刚刚在我的应用程序中注册的用户在 facebook 或 twitter 上的现有图像上传到 amazon s3,但某些验证不允许我保存用户对象,抛出:Image is invalid.I以为那是给我的 extension_white_list 但我删除了它,它一直在说Image is invalid.

  • 这不是错误,我认为这只是来自carrierwave 验证的消息,即使图像网址字符串是正确的。

头像上传

# 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
...

【问题讨论】:

  • 您是否检查了使用 SDK 进行 s3 操作的日志?如果上传不起作用,它应该为您提供更多信息。 url在浏览器中使用时有效吗?
  • 是的,该网址有效。不,因为验证失败而没有上传图片。
  • 您是否从 SDK 中获取任何日志?如果 url 在获取图像时是正确的,那么它可能是为上传生成签名的问题

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


【解决方案1】:

已修复!该错误与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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-07
    • 2017-01-29
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多