EXCON ::错误::禁止在UsersController中#更新 [英] Excon::Errors::Forbidden in UsersController#update

查看:435
本文介绍了EXCON ::错误::禁止在UsersController中#更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Carrierwave上传图片到Amazon S3提供我的用户有机会上传头像。

I'm trying to use Carrierwave to upload images to Amazon S3 to provide my users to opportunity to upload avatars.

当我添加一个图像文件,然后单击更新,我得到了以下错误消息:

When I add an image file and click "Update," I get the following error message:

Excon::Errors::Forbidden in UsersController#update
Expected(200) <=> Actual(403 Forbidden) excon.error.response :body => "<?xml version=\"1.0\"     encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message>    <RequestId>67D635476E2363B7</RequestId>    <HostId>Aw9W8C1ShJt73UGE6IuRZAOK6UkWM46hy+noygWCZAR2Has1lrCDpZkcgX2+7y7b</HostId></Error>" :headers     => { "Connection" => "close" "Content-Type" => "application/xml" "Date" => "Sun, 14 Dec 2014 21:21:35     GMT" "Server" => "AmazonS3" "x-amz-id-2" =>     "Aw9W8C1ShJt73UGE6IuRZAOK6UkWM46hy+noygWCZAR2Has1lrCDpZkcgX2+7y7b" "x-amz-request-id" =>     "67D635476E2363B7" } :local_address => "192.168.195.234" :local_port => 56281 :reason_phrase =>     "Forbidden" :remote_ip => "54.231.64.217" :status => 403

我的UsersController中#更新为:

My UsersController#Update is:

 def update
  if current_user.update_attributes(user_params)
  flash[:notice] = "User information updated"
  redirect_to edit_user_registration_path
 else
  flash[:notice] = "Invalid User information"
  redirect_to edit_user_registration_path
end
end

  private

   def user_params
     params.require(:user).permit(:name, :avatar)
   end

我的形式更新头像是:

My form for updating the avatar is:

    .form-group
      = f.label :name
      = f.text_field :name, class: 'form-control', placeholder: 'Enter name', autofocus: true
    - if current_user.avatar?
      .form-group
        %p Current avatar
        = image-tag(current_user.avatar.profile.url)
    .form-group
      = f.label :avatar
      = f.file_field :avatar 
      = f.hidden_field :avatar_cache 

    .form-group
      = f.submit 'Update', class: 'btn btn-success'

我发现的StackOverflow类似的问题,而答案也不得不做选择的桶区域;但S3不需要区域了。 。

I found a similar question on StackOverflow, and the answer there had to do with the region selected for the bucket; but S3 doesn't require regions anymore . . .

我不熟悉EXCON,我不知道任何的错误消息我得到的。

I'm not familiar with Excon, and I don't understand any of the error messages I'm getting.

有没有人有什么建议?

谢谢!

推荐答案

以防万一别人运行到这个问题,下面是它如何工作对我来说:

Just in case anyone else runs into this problem, here's how it worked out for me:

我使用的是Amazon S3的IAM用户,其访问和密钥我会用这个应用程序没有权限的用户。哎呀。 。

I'm using IAM users on Amazon S3, and the user whose access and secret keys I'd used for this app had no permissions. Oops . . .

所以,我给了用户电力用户和管理权限,和我的头像是正确加载!

So, I gave that user Power User and Administrative permissions, and my avatars are loading properly!

这篇关于EXCON ::错误::禁止在UsersController中#更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆