开发者

Got S3::Error::SignatureDoesNotMatch by using Paperclip with "s3" on certain path configuration

开发者 https://www.devze.com 2023-04-01 19:51 出处:网络
Hi I got the below in certain path configuration: S3::Error::SignatureDoesNotMatch (The request signature we calculated does not match thesignature you provided. Check your key and signing method.):

Hi I got the below in certain path configuration:

S3::Error::SignatureDoesNotMatch (The request signature we calculated does not match the      signature you provided. Check your key and signing method.):
    config/initializers/paperclip_2_s3.rb:124:in `block in flush_writes'
    config/initializers/paperclip_2_s3.rb:113:in `each'
    config/initializers/paperclip_2_s3.rb:113:in `flush_writes'
    app/controllers/admin/images_controller.rb:12:in `create'

has_mongoid_attached_file :photo,
                :styles => { :thumb => "120x120#" },
                :convert_options => { :all => "-quality 92 +profile '!icc,*'" },
                :storage => :s3,
                # :path => '/:class/:attachment/:style/:basename.:extension',
                :path => ':class/:attachment/:id_partition/:basename.:style.:extension',
                :url => ':s3_domain_url',
                :s3_credentials => {
                  :access_key_id => ApplicationController.aws_access_key,
                  :secret_access_key => ApplicationController.aws_secret_access_key
                },
                :bucket => proc { |attachment| if attachment.instance.imagable.respond_to? (:domain) then ApplicationController.bucket_name(attachment.instance.imagable.domain) else ApplicationController.bucket_name(attachment.instance.imagable.site.domain) end }

If I change the configuration to this one:

has_mongoid_attached_file :photo,
                :styles => { :thumb => "120x120#" },
                :convert_options => { :all => "-quality 92 +profile '!icc,*'" },
                :storage => :s3,
                # :path => '/:class/:attachment/:style/:basename.:extension',
                :path => ':class/:attachment/:id_partition/:basename.:style.:extension',
                :url => ':s3_domain_url',
                :s3_credentials => {
                  :access_key_id => ApplicationController.aws_access_key,
                  :secret_access_key => ApplicationController.aws_secret_access_key
                },
                :bucket => proc { |attachment| if attachment.instance.imagable.respond_to? (:domain) then ApplicationController.bucket_name(attachment.instance.imagable.domain) else ApplicationController.bucket_name(attachment.instance.imagable.site.domain) end }

Then everything is ok....

So I changed only the storage path

# :path => '/:class/:attachment/:style/:basename.:extension',
:pat开发者_如何转开发h => ':class/:attachment/:id_partition/:basename.:style.:extension',

This works also:

:path => ':class/:attachment/:id_partition/:basename:style.:extension',

Can anybody explain this?

Another interesting thing:

:path => '/:id_partition/:basename.:extension',

in this case I also got this:

URI::InvalidURIError (the scheme  does not accept registry part: 4e5e (or bad hostname?)):

Any explanations are welcome... :)


After inspecting the code of the S3 code, it reveals that the :id or the partitioned version :id_partition must be a necessary thing in the path.

0

精彩评论

暂无评论...
验证码 换一张
取 消