2011-08-31 74 views
2

嗨“S3”我得到了下面的某些路径配置:了S3 ::错误:: SignatureDoesNotMatch通过使用回形针对某些路径配置

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 } 

如果我更改配置为这一个:

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 } 

然后一切都很好....

所以我只更改了存储路径

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

这工作也:

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

任何人能解释一下吗?

另一个有趣的事情:

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

在这种情况下,我也拿到了这一点:

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

任何解释,欢迎... :)

回答

0

检查S3的代码后代码,它揭示了:id或分区版本:id_partition必须是路径中必需的东西。