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
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'
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 . . .
I'm not familiar with Excon, and I don't understand any of the error messages I'm getting.
Does anyone have any suggestions?
Thanks!