0

我正在使用回形针在 Amazon S3 上存储图片。如果我通过普通表单上传它可以正常工作,但如果他们通过omniauth注册Facebook,我还想将用户的个人资料图片默认设置为他们的Facebook图片。

它正确设置图片文件大小、名称和所有其他字段。我打电话时它甚至设置了正确的链接

 <%= image_tag @user.profile_picture.url(:small) %>

但由于某种原因,图像没有被存储。

同样,如果我使用表单上传,它会很好地上传图片。

  <%= f.label :profile_picture %>
  <%= f.file_field :profile_picture %>

我如何尝试从注册链接中解析图像:

user.profile_picture=URI.parse(auth.info.image)

我的回形针配置:

  has_attached_file :profile_picture, styles: { small: "150x150>" },
                    path: "app/public/uploads/profile_pictures/:id/:style/:basename.:extension",
  validates_attachment_content_type :profile_picture, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
  validates_attachment_size :profile_picture, less_than: 2.megabytes

我的生产.rb:

  config.paperclip_defaults = {
      :storage => :s3,
      :s3_credentials => {
          :bucket => ENV['S3_BUCKET_NAME'],
          :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
          :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
      }
  }

Paperclip.rb 初始化器:

Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-west-1.amazonaws.com'
4

0 回答 0