在某些路径配置上使用Paperclip并使用“s3”获得S3 :: Error :: SignatureDoesNotMatch

时间:2011-08-31 21:00:04

标签: ruby amazon-s3 paperclip

嗨,我在某些路径配置中得到了以下内容:

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?)):

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

1 个答案:

答案 0 :(得分:0)

在检查S3代码的代码之后,它显示:id或分区版本:id_partition必须是路径中的必要内容。