2016-11-12 97 views
0

我試圖通過Facebook註冊創建一個用戶使用回形針和使用亞馬遜S3到我的網站,以便存儲用戶頭像。我希望用戶能夠將頭像添加到他們的個人資料中,但似乎我被拒絕訪問。我已經看過並嘗試了幾種解決方案,但都沒有成功。保存用戶頭像上回形針和Aws :: S3 ::錯誤:: AccessDenied

這裏是我的瀏覽器中的錯誤:

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", "[email protected]"], ["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

回答

0

聽起來像是S3存儲桶上的許可問題,與您的代碼無關。