【问题标题】:Heroku S3 Paperclip Doesn't workHeroku S3 回形针不起作用
【发布时间】:2015-04-17 08:27:41
【问题描述】:

我在使用回形针和 heroku 时遇到问题,真的需要帮助。过去 2 天我一直被困在这个问题上,我找不到的链接都没有帮助:

https://github.com/igor-alexandrov/paperclip-aws"
"http://www.codeitive.com/0QHVXqkUVV/heroku-paperclip-s3-error-%3E-    awss3errorssignaturedoesnotmatch.html"
"https://devcenter.heroku.com/articles/paperclip-s3#international-users-additional-configuration"
"http://dchua.com/2011/12/27/how-to-get-paperclip-and-aws-s3-singapore-and-european-buckets-working/"
"http://www.kahfei.com/?p=389"
"http://www.conandalton.net/2011/02/paperclip-s3-and-european-buckets.html"
"http://stackoverflow.com/questions/20424724/ruby-on-rails-paperclip-amazon-aws-s3-heroku"
"http://stackoverflow.com/questions/7257745/rails-3-amazon-s3-paperclip-eu-problem"

一开始我想使用欧洲 S3 位置,但由于它似乎让一切变得更加复杂,我决定切换回默认的美国位置。

我在终端上设置了我的 VARS:

$ heroku config:set S3_BUCKET_NAME=your_bucket_name
$ heroku config:set AWS_ACCESS_KEY_ID=your_access_key_id
$ heroku config:set AWS_SECRET_ACCESS_KEY=your_secret_access_key

然后在我的 config/environment/production.rb 中:

config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}

访问我的网站并尝试上传图片时,我的 heroku 日志如下:

Running `bundle exec rake db:seed` attached to terminal... up, run.8070
rake aborted!
AWS::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:375:in `return_or_raise'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:476:in `client_request'
(eval):3:in `put_object'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/s3_object.rb:1765:in `write_with_put_object'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/s3_object.rb:611:in `write'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:360:in `block in flush_writes'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:331:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/storage/s3.rb:331:in `flush_writes'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/attachment.rb:238:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-meta-1.2.0/lib/paperclip-meta/attachment.rb:16:in `save_with_meta_data'
/app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.2.1/lib/paperclip/has_attached_file.rb:91:in `block in add_active_record_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:441:in `instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:225:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:225:in `block in halting_and_conditional'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/callbacks.rb:302:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:142:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/validations.rb:43:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:291:in `block in save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:291:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:51:in `create!'
/app/db/seeds.rb:9:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed

显然我已经仔细检查了我的 heroku 配置并尝试再次输入密钥和存储桶 => 没有变化。

在这一点上,我尝试了很多东西,以至于我迷路了。 在 attach_files 之后在我的模型中设置 heroku 的东西 除了 heroku config var 之外,还设置 heroku YAML 文件 尝试了欧洲和美国标准水桶

如果有人有任何想法.. 我对该错误所做的所有研究都没有帮助:AWS::S3::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.

【问题讨论】:

  • 它在本地工作吗?您使用的是哪个版本的回形针?我知道你说过你仔细检查了你的heroku config,但再次检查你没有交换你的访问密钥 ID 和密钥...... :)
  • 我没有在本地尝试过。我认为它会更简单。我现在正在这样做并且“缺少必需的:bucket 选项”我想这是需要研究的东西。很奇怪,我在尝试解决我的问题时在 stackoverflow 上一次又一次地看到该错误,但我第一次看到它。我怀疑它来自我的本地配置,而不是与其他错误有关。
  • 好吧,去本地工作吧
  • 好,现在可以直播了
  • 是的,它正在现场工作。但这与 heroku 回形针教程所说的相去甚远。

标签: ruby-on-rails heroku amazon-s3


【解决方案1】:

好吧,让它继续工作,以便下一个人遇到这个问题:

-不要遵循heroku回形针教程

-在您的配置文件夹中创建一个 aws.yml 文件:

development:
  access_key_id: "xxxxxinquote"
  secret_access_key: "yyyyyinquote"
test:
  access_key_id: abc...
  secret_access_key: abc...
production:
  access_key_id: "xxx"
  secret_access_key: "yyyy"

-在所有带有文件上传的模型中放置:

has_attached_file :image,
                  :styles => { :medium => "460x>", :thumb => "100x100>",:vnice=> "400x" },
                  :storage => :s3,
                  :bucket => 'hohohohoho',
                  :s3_credentials => "#{Rails.root}/config/aws.yml",
                  :path => "resources/:id/:style/:basename.:extension

然后在您的生产或/和 dev.rb 中

config.paperclip_defaults = {
  :storage => :s3,
    :bucket => ENV['S3_BUCKET_NAME'],
  :s3_credentials => {
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}

注意 :bucket 在 s3 凭证之外,与教程中所说的不同。

希望对大家有所帮助

【讨论】:

  • 我现在遇到了回形针和 heroku 的问题。我以后一定会试试的。
猜你喜欢
  • 2011-07-31
  • 2017-05-13
  • 2011-08-09
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
相关资源
最近更新 更多