Errors::SignatureDoesNotMatch, AWS-SDK gem for S3 support on paperclip 3.0.1 and rails 3.2
Asked Answered
S

3

14

I'm migrating my app from Rails 3.0.9 to 3.2.3 and ruby 1.9.3. I was using paperclip(2.3.11) with aws-s3 gem to store my pictures.

Now I want to use the last version of paperclip(3.0.1) and then I have to use aws-sdk gem.

I've set my aws.yml file as:

    development: &development
      bucket: bucket_name_for_dev
      access_key_id: *****
      secret_access_key: *******
    staging:
      <<: *development
      bucket: bucket_name_for_staging

    production:
      <<: *development
      bucket: bucket_name_for_prod

my model contains :

    has_attached_file :picture, :styles => { :medium => "300x300>", :thumb => "50x50>" }, :default_url => 'picture_missing.png',
         :storage => :s3,
         :bucket => "bucket_name_for_dev",
         :s3_credentials => Rails.root.join("config/aws.yml"),
         :path => "/presentation_pictures/:id/:style/:filename",
         :url  => ":s3_eu_url"

    attr_accessible :picture
    attr_accessor :picture_url

When trying to upload a file, I get the error:

AWS::S3::Errors::SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method.

I verified that my keys are accessible and set to the right value.

Here is also what I get from console:

    [paperclip] Saving attachments.
    [paperclip] saving /presentation_pictures/43/original/Image_1.png
    [AWS S3 200 0.813272 0 retries] put_object(:acl=>:public_read,:bucket_name=>"*******_dev",:content_type=>"image/png",:data=>#<Paperclip::UploadedFileAdapter:0x2e144b4 @target=#<ActionDispatch::Http::UploadedFile:0x2dbb1fc @original_filename="Image 1.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"presentation_picture[picture]\"; filename=\"Image 1.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/var/folders/tb/tbmv4LE9EwGNPr1QqU2S0E+++TI/-Tmp-/RackMultipart20120407-33502-1gajfe9>>, @tempfile=#<File:/var/folders/tb/tbmv4LE9EwGNPr1QqU2S0E+++TI/-Tmp-/Image 1.png20120407-33502-an4dcy>>,:key=>"presentation_pictures/43/original/Image_1.png")

Do you have any idea from where could come this problem? Thx

Sanity answered 7/4, 2012 at 9:52 Comment(1)
I don't have an answer for you but you could post your aws-sdk and aws-s3 versions from Gemfile.lock? I'm trying to figure out why this started happening for me too.Excretory
M
16

I had the same issue. It turned out I was using the correct access key id but my secret key was copied incorrectly.

Double checking my secret key and correcting it fixed it for me.

Mythify answered 19/6, 2014 at 3:52 Comment(1)
Yep... 2x-click, copy and paste can lead to funny results AWS uses characters that break up the key as separate words.Bayou
U
3

My mistake was taking the root access key instead of the user access key. AWS changed it recently so you must create an individual AIM user for yourself, and then use that user's access key (not root)

Uraninite answered 10/7, 2017 at 20:47 Comment(1)
Yeah, creating a non root user did it for me.Premeditate
S
1

Seems like you cannot access your aws the right way. You have to specify your host name, especially when using buckets in a non US region. Try using

:s3_host_name => 's3-eu-west-1.amazonaws.com'

in your has_attached_file options.

If you've configured your S3 to use https also add

:s3_protocol => 'https' 

if not, just ignore it.

And if your bucket is a private one, add

:s3_permissions => :private

You also don't need to explicitly configure your bucket in the options parameter, as you've already declared it in your aws.yml and set it via :s3_credentials => Rails.root.join("config/aws.yml").

Hope this helps.

Sarthe answered 2/7, 2012 at 7:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.