【发布时间】:2015-06-01 03:43:39
【问题描述】:
我正在尝试使用 Carrierwave 将图像上传到 Amazon 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 不熟悉,也不了解收到的任何错误消息。
有人有什么建议吗?
谢谢!
【问题讨论】:
标签: amazon-s3 carrierwave