我正在尝试使用Carrierwave将图片上传到亚马逊S3,为我的用户提供上传头像的机会。
当我添加一个图像文件并单击“更新”时,我得到以下错误消息:
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#Update是:
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我更新头像的表单是:
.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不再需要区域。。。
我不熟悉Excon,我也不理解我收到的任何错误消息。
有人有什么建议吗?
谢谢!
发布于 2014-12-15 05:55:25
为了防止其他人遇到这个问题,下面是我的解决方案:
我在亚马逊S3上使用IAM用户,而我在此应用程序中使用的访问权限和密钥没有权限。糟了。。。
所以,我给了用户超级用户和管理权限,我的头像可以正常加载了!
发布于 2015-06-01 03:43:40
Amazon AWS管理控制台>> Users >> Select IAM User >> Attach Policy >> AmazonS3FullAccess
https://stackoverflow.com/questions/27474431
复制相似问题