S3 存储因雾 0.7.2 而失败 +载波主干分支

发布于 2024-11-06 12:09:06 字数 3898 浏览 0 评论 0原文

当尝试存储文件时,我得到以下信息:

TypeError: can't convert nil into String
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:23:in `digest'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:23:in `block in setup_sha1'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:15:in `call'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:15:in `sign'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/aws.rb:309:in `signature'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/aws.rb:317:in `request'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/requests/aws/put_object.rb:43:in `put_object'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/models/aws/file.rb:119:in `save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/collection.rb:50:in `create'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/storage/fog.rb:229:in `store'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/storage/fog.rb:79:in `store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/uploader/store.rb:59:in `block in store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/uploader/store.rb:58:in `store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/mount.rb:324:in `store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/mount.rb:214:in `store_poster!'
... 3 levels...
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/validations.rb:43:in `save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/attribute_methods/dirty.rb:21:in `save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:240:in `block (2 levels) in save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:207:in `transaction'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:240:in `block in save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:239:in `save'
    from (irb):2
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'

我尝试手动调试,我想知道该问题是否与 @content_type 被设置为 nil 的事实有关,尽管我无法进一步推断出更多信息。

这是一个 s3(或雾,我没有任何其他提供程序)特定问题,并且我的项目在使用 :file 存储时工作正常。想法?

When trying to store a file I get the following:

TypeError: can't convert nil into String
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:23:in `digest'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:23:in `block in setup_sha1'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:15:in `call'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/hmac.rb:15:in `sign'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/aws.rb:309:in `signature'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/aws.rb:317:in `request'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/requests/aws/put_object.rb:43:in `put_object'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/storage/models/aws/file.rb:119:in `save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/fog-0.7.2/lib/fog/core/collection.rb:50:in `create'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/storage/fog.rb:229:in `store'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/storage/fog.rb:79:in `store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/uploader/store.rb:59:in `block in store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/uploader/store.rb:58:in `store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/mount.rb:324:in `store!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/bundler/gems/carrierwave-d2cb99103a4f/lib/carrierwave/mount.rb:214:in `store_poster!'
... 3 levels...
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/validations.rb:43:in `save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/attribute_methods/dirty.rb:21:in `save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:240:in `block (2 levels) in save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:207:in `transaction'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:240:in `block in save'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:239:in `save'
    from (irb):2
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
    from /Users/nick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'

I've tried to debug manually and I wonder whether the issue ties in with the fact @content_type is being set as nil, although I haven't been able to deduce much further than that.

This is an s3 (or fog, I don't have any other providers) specific issue and my project works fine when using :file storage. Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城空念 2024-11-13 12:09:06

这个问题正好困扰了我。我通过将其放入 config/initializers/rierwave.rb 中解决了这个问题:

S3_CONFIG = YAML.load_file(Rails.root.join('config', 'amazon_s3.yml'))[Rails.env]

CarrierWave.configure do |config|
  config.storage              = :s3
  config.s3_access_policy     = :public_read
  config.s3_access_key_id     = S3_CONFIG['access_key_id']
  config.s3_secret_access_key = S3_CONFIG['secret_access_key']
  config.s3_bucket            = S3_CONFIG['bucket']
end

并将其放入 config/amazon_s3.yml 中:

development:
  access_key_id: xxxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: your-dev-bucket

test:
  access_key_id: xxxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: your-test-bucket

production:
  access_key_id: xxxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: your-prod-bucket

This problem just bit me. I solved it by putting this in config/initializers/carrierwave.rb:

S3_CONFIG = YAML.load_file(Rails.root.join('config', 'amazon_s3.yml'))[Rails.env]

CarrierWave.configure do |config|
  config.storage              = :s3
  config.s3_access_policy     = :public_read
  config.s3_access_key_id     = S3_CONFIG['access_key_id']
  config.s3_secret_access_key = S3_CONFIG['secret_access_key']
  config.s3_bucket            = S3_CONFIG['bucket']
end

and putting this in config/amazon_s3.yml:

development:
  access_key_id: xxxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: your-dev-bucket

test:
  access_key_id: xxxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: your-test-bucket

production:
  access_key_id: xxxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: your-prod-bucket
就像说晚安 2024-11-13 12:09:06

解决了。我使用的是自述文件中规定的过时配置,而不是文档中规定的新方法。

Carrierwave 的新开发人员一定要阅读实际的 RDOC,而不是自述文件。

Solved. I was using the out-dated configuration stated in the README rather than the new method stating within the documentation.

New developers to carrierwave be sure to read the actual RDOC, not the readme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文