Image invalid on facebook/twitter user image uploading to S3
Asked Answered
F

1

0

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
...
Foetation answered 5/12, 2012 at 19:32 Comment(3)
Did you check the logs for s3 operation using the SDK? It should give you more information if the upload did not work. Does the url work when you use it in the browser?Vala
Yes, the url works. No, the image it not being uploaded because validation failed.Foetation
Do you get any logs out from the SDK? If the url is right in fetching the image then it could be a problem with signature being generated for the uploadVala
F
2

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
Foetation answered 6/12, 2012 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.