无法加载Rails.config.active_storage.service

Sim*_*per 6 ruby-on-rails amazon-s3 rails-activestorage ruby-on-rails-5.2

我正在使用Active Storage设置新的Rails 5.2应用程序,并使用AWS托管生产中的图像。

但是,我在读取凭据时遇到问题:

2018-07-06T08:11:52.625415+00:00 app[web.1]: ! Unable to load application: Aws::Sigv4::Errors::MissingCredentialsError: Cannot load `Rails.config.active_storage.service`:
2018-07-06T08:11:52.625432+00:00 app[web.1]: missing credentials, provide credentials with one of the following options:
2018-07-06T08:11:52.625435+00:00 app[web.1]:   - :access_key_id and :secret_access_key
2018-07-06T08:11:52.625437+00:00 app[web.1]:   - :credentials
2018-07-06T08:11:52.625479+00:00 app[web.1]:   - :credentials_provider
Run Code Online (Sandbox Code Playgroud)

这是现有的S3存储桶,我为此应用创建了一个新用户。我对CORS等感到满意。

在S3FullAccess组下设置用户。

我已经通过修改了我应用程序中的凭据 $EDITOR="atom --wait" rails credentials:edit

文件内容:

aws:
  access_key_id: [my access key]
  secret_access_key: [my secrect key]

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: [my secret key base]
Run Code Online (Sandbox Code Playgroud)

请注意,这是YAML格式的,我使用过一个空格,并且在键上使用了一个制表符,但这似乎没有什么不同。

当我保存并关闭文件时,终端将写入 New credentials encrypted and saved.

我也gem 'aws-sdk-s3', '~>1', require: false安装了。

和config / storage.yml

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: eu-west-2
  bucket: [mybucket]
Run Code Online (Sandbox Code Playgroud)

关于我可能在做错的任何建议吗?

小智 7

我认为您缺少master.key服务器中的文件。检查您的本地仓库config/master.key.gitignore默认情况下此文件已添加到您的仓库中)。将此文件添加到服务器或设置ENV["RAILS_MASTER_KEY"]


isp*_*ett 5

这在 Heroku 上对我有用:在“设置 > 配置变量”中添加一个RAILS_MASTER_KEY键,并将文件的内容config/master.key(来自 Rails 应用程序)作为值。

  • 谢谢你!我刚刚被这个刺痛了。对于其他人的快速提示,请尝试: `heroku config:set RAILS_MASTER_KEY=$(echo ./config/credentials/product.key)` (2认同)