简体   繁体   English

在回形针和Aws :: S3 :: Errors :: AccessDenied上保存用户头像

[英]saving user avatar on paperclip and Aws::S3::Errors::AccessDenied

I am attempting to signup through Facebook to create a user with avatar using paperclip and using Amazon S3 to my site so to store user avatars. 我试图通过Facebook注册以使用回形针创建一个具有化身的用户,并使用Amazon S3到我的网站,以便存储用户化身。 I expect users to be able to add an avatar to their profiles but it seems that I am denied access. 我希望用户能够在其个人资料中添加头像,但似乎我被拒绝访问。 I've looked at and tried several solutions with no success. 我查看并尝试了几种解决方案,但均未成功。

Here are the errors on my browser: 这是我的浏览器中的错误:

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

Extracted source (around line #19): 提取的源(第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'

here is the user.rb: 这是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

My github repo: https://github.com/zivolution921/tinstuk 我的github回购: https : //github.com/zivolution921/tinstuk

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM