tried to find the cause of this error for a long time and cannot find any ...
So, I have a rails application, and I'm using a carrier wave to load images. I also want to use Amazon S3 to store files in my application.
Initially, when I develop the application, I allowed the upload of files to the on: file. ie
image_uploader.rb
# Choose what kind of storage to use for this uploader: storage :file # storage :fog
Now, having finished the development and placing it live (I use the hero), I decided to change the carrier storage to S3 to check it locally.
image_uploader.rb
# Choose what kind of storage to use for this uploader: # storage :file storage :fog
However, now when I try to upload an image (be it a user avatar, etc.), I get this error:
Excon::Errors::Forbidden in UsersController#update Expected(200) <=> Actual(403 Forbidden) request => {:connect_timeout=>60, :headers=>{"Content-Length"=>74577, "x-amz- acl"=>"private", "Content-Type"=>"image/png", "Date"=>"Sun, 26 Feb 2012 10:00:43 +0000", "Authorization"=>"AWS AKIAJOCDPFOU7UTT4HOQ:8ZnOy7X71nQAM87yraSI24Y5bSw=", "Host"=>"s3.amazonaws.com:443"}, :instrumentor_name=>"excon", :mock=>false, :read_timeout=>60, :retry_limit=>4, :ssl_verify_peer=>true, :write_timeout=>60, :host=>"s3.amazonaws.com", :path=>"/uploads//uploads%2Fuser%2Favatar%2F1%2Fjeffportraitmedium.png", :port=>"443", :query=>nil, :scheme=>"https", :body=>"\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\xC2\x00\x00\x00\xC3\b\x06\x00\x00\x00\xD0\xBD\xCE\x94\x00\x00\nCiCCPICC Profile\x00\x00x\x01\x9D\x96wTSY\x13\xC0\xEF{/\xBD\xD0\x12B\x91\x12z\rMJ\x00\x91\x12z\x91^E%$\ ... # The code you see above to the far right repeats itself a LOT ... 1@ \x85\xB5\t\xFC_y~\xA6=:\xB2\xD0^\xBB~i\xBB\x82\x8F\x9B\xAF\xE7\x04m\xB2i\xFF\x17O\x94S\xF7l\x87\xA8&\x00\x00\x00\x00IEND\xAEB`\x82", :expects=>200, :idempotent=>true, :method=>"PUT"} response => #<Excon::Response:0x007fc88ca9f3d8 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>8EFA56C0DDDC8878</RequestId><HostId>1OxWXppSSUq1MFjQwvnFptuCM3gKOuKdlQQyVSEgvzzv4Aj+r2hSFM2UUw2NYyrR</HostId></Error>", @headers={"x-amz-request-id"=>"8EFA56C0DDDC8878", "x-amz-id-2"=>"1OxWXppSSUq1MFjQwvnFptuCM3gKOuKdlQQyVSEgvzzv4Aj+r2hSFM2UUw2NYyrR", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Sun, 26 Feb 2012 10:00:47 GMT", "Connection"=>"close", "Server"=>"AmazonS3"}, @status=403>
And then he says this also for my application trace:
app/controllers/users_controller.rb:39:in `update'
And my REQUEST parameters:
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"DvADD1vYpCLcghq+EIOwVSjsfmAWCHhtA3VI5VGD/q8=", "user"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007fc88cde76f8 @original_filename="JeffPortraitMedium.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"JeffPortraitMedium.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/var/folders/vg/98nv58ss4v7gcbf8px_8dyqc0000gq/T/RackMultipart20120226- 19096-1ppu2sr>>, "remote_avatar_url"=>"", "name"=>"Jeff Lam ", "email"=>" email@gmail.com ", "user_bio"=>"Tester Hello", "shop"=>"1"}, "commit"=>"Update Changes", "id"=>"1"}
Here is my incomplete users_controller.rb code:
def update @user = User.find(params[:id]) if @user.update_attributes(params[:user]) redirect_back_or root_path flash[:success] = "Your have updated your settings successfully." else flash.now[:error] = "Sorry! We are unable to update your settings. Please check your fields and try again." render 'edit' end end
My code is image_uploader.rb
# encoding: utf-8 class ImageUploader < CarrierWave::Uploader::Base
Finally, my fog.rb file in config / initializers
CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS',
Actually, I am very confused by some things in my fog.rb. First, do I have to change my region to Singapore if I created a bucket called "ruuva", with the "Singapore" region on my amazon s3 account?
Thanks to everyone who can help in advance!