【问题标题】:saving user avatar on paperclip and Aws::S3::Errors::AccessDenied在回形针和 Aws::S3::Errors::AccessDenied 上保存用户头像
【发布时间】:2016-11-13 04:36:25
【问题描述】:

我正在尝试通过 Facebook 注册以使用回形针创建具有头像的用户,并在我的网站上使用 Amazon S3 来存储用户头像。我希望用户能够将头像添加到他们的个人资料中,但似乎我被拒绝访问。我已经查看并尝试了几种解决方案,但均未成功。

以下是我浏览器上的错误:

Aws::S3::Errors::AccessDenied in SessionsController#create
Access Denied

提取的源代码(第 19 行附近):

17
18
19    def self.create_user_from_facebook(auth)
        create(
        avatar: process_uri(auth['info']['image'] + "?width=9999"),
        email: auth['info']['email'],
        provider: auth['provider'],

in the commnad-line errors: 
 SQL (0.6ms)  INSERT INTO "users" ("provider", "uid", "name", "email", "created_at", "updated_at", "avatar_file_name", "avatar_content_type", "avatar_file_size", "avatar_updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["provider", "facebook"], ["uid", "10209320526747935"], ["name", "Ziv Steeven Zamechek"], ["email", "ziv921@yahoo.com"], ["created_at", 2016-11-12 18:15:38 UTC], ["updated_at", 2016-11-12 18:15:38 UTC], ["avatar_file_name", "picture"], ["avatar_content_type", "image/jpeg"], ["avatar_file_size", 15297], ["avatar_updated_at", 2016-11-12 18:15:38 UTC]]
[paperclip] saving /users/avatars/000/000/001/original/picture
   (0.3ms)  rollback transaction
Completed 500 Internal Server Error in 409ms (ActiveRecord: 1.8ms)



Aws::S3::Errors::AccessDenied (Access Denied):

app/models/user.rb:19:in `create_user_from_facebook'
app/models/user.rb:15:in `sign_in_from_facebook'
app/controllers/sessions_controller.rb:6:in `create'

这里是 user.rb:

class User < ActiveRecord::Base

    has_many :friendships, dependent: :destroy
    has_many :inverse_friendships, class_name: "Friendship", foreign_key: "friend_id", dependent: :destroy

    has_attached_file :avatar,
                      :storage => :s3,
                      :style => { :medium => "370x370", :thumb => "100x100" }

    validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

    default_scope { order('id DESC') }

    def self.sign_in_from_facebook(auth)
        find_by(provider: auth['provider'], uid: auth['uid'] ) || create_user_from_facebook(auth)
    end

    def self.create_user_from_facebook(auth)
        create(
        avatar: process_uri(auth['info']['image'] + "?width=9999"),
        email: auth['info']['email'],
        provider: auth['provider'],
        uid: auth['uid'],
        name: auth['info']['name'],
        gender: auth['extra']['raw_info']['gender'],
        date_of_birth: auth['extra']['raw_info']['birthday'],
        location: auth['info']['location'],
        bio: auth['extra']['raw_info']['bio']
        )
    end
end

我的 github 仓库: https://github.com/zivolution921/tinstuk

【问题讨论】:

    标签: ruby-on-rails amazon-s3 paperclip


    【解决方案1】:

    听起来像是您的 S3 存储桶的权限问题,与您的代码无关。

    【讨论】:

      猜你喜欢
      • 2019-12-18
      • 2018-07-06
      • 2017-04-24
      • 2016-06-26
      • 2016-12-21
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多