图像在Facebook / Twitter的用户图像上传到S3无效 [英] Image invalid on facebook/twitter user image uploading to S3

查看:161
本文介绍了图像在Facebook / Twitter的用户图像上传到S3无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传到Amazon S3在Facebook或Twitter从刚刚签署了在我的应用程序的用户,但一些验证不要让我节省了用户对象现有图像,抛出:图像是无效的。我认为这是对我的extension_white_list,但我删除它和它保持说法图像是无效的。

  • 这是不是一个错误,这是从carrierwave验证我觉得只是一个消息,即使图像的URL字符串是正确的。

AvatarUploader

 #编码:UTF-8

类AvatarUploader< CarrierWave ::上传::基地

  包括CarrierWaveDirect ::上传

  包括CarrierWave :: RMagick

  #包括链轮佣工的Rails 3.1+资产管道兼容性:
  包括链轮::助手:: RailsHelper
  包括链轮::助手:: IsolatedHelper

  包括CarrierWave :: MIMETYPES
  过程:set_content_type

  高清store_dir
    阿凡达/#{model.id}
  结束

  版本:拇指做
    过程resize_to_fill:[50,50]
  结束

  #高清extension_white_list
  #%(重量)(JPG JPEG GIF PNG,BMP)
  # 结束
结束
 

创建用户:

  ...
    new_user = User.create(:名称=>权威性['信息'] ['名称'],
                     :电子邮件=> User.email_from_auth(AUTH))
    auth_image_url = Authentication.larger_image(AUTH)#从社交网络身份验证数据的字符串用户图像的URL。即:http://a0.twimg.com/profile_images/1255111511/skyline.jpg
    除非auth_image_url.blank?
      new_user.remote_image_url = auth_image_url
      new_user.save
    结束
...
 

解决方案

固定!该错误已无关carrierwave,只是对象不数据库存在于当下的事实,其中图像上传,首先我保存新的用户,然后:

  after_create:upload_image_from_auth

高清upload_image_from_auth
  AUTH = self.authentications.first
  除非auth.nil?
    self.remote_image_url = auth.larger_image
    self.save
  结束
结束
 

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

解决方案

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

这篇关于图像在Facebook / Twitter的用户图像上传到S3无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆