Image invalid on facebook/twitter user image uploading to S3

元气小坏坏 提交于 2019-12-12 04:33:16

问题


I'm trying to upload to amazon s3 an existing image on facebook or twitter from an user that has just signed up in my application, but some validation don't let me save the user object, throws: Image is invalid. I thought that was for my extension_white_list but I removed it and it's keeping saying Image is invalid.

  • This it's not an error, it's just a message from a validation on carrierwave I think, even if the image url string is correct.

AvatarUploader

# 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

Creating user:

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

回答1:


Fixed! The error has nothing to do with carrierwave, just the fact that the object does not exist on database in the moment where the image is upload, first I save the new user and then:

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


来源:https://stackoverflow.com/questions/13730976/image-invalid-on-facebook-twitter-user-image-uploading-to-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!