在paperclip和Aws :: S3 :: Errors :: AccessDenied上保存用户头像

时间:2016-11-12 18:29:47

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

我正试图通过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

1 个答案:

答案 0 :(得分:0)

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