【发布时间】:2018-06-10 04:13:35
【问题描述】:
我已经为此工作了几个小时,但无法弄清楚。我跑了 git clean 然后意识到我的 s3.yml 文件被删除了。我创建了新密钥并将它们放在一个新的 s3.yml 文件中。我没有改变以前工作得很好的任何其他东西。我错过了什么?
我收到:Aws::Errors::MissingCredentialsError (unable to sign request without credentials set):
这是我的代码:
开发.rb
config.paperclip_defaults = {
storage: :s3,
s3_region: 'us-east-1',
bucket:'mybucket',
s3_credentials: "#{Rails.root}/config/s3.yml"
}
生产.rb
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
}
}
# Secret key base for non-existent secrets.yml file
config.secret_key_base = ENV["SECRET_KEY_BASE"]
s3.yml(带有新的访问密钥)
S3_BUCKET_NAME: mybucket
AWS_ACCESS_KEY_ID: ***
AWS_SECRET_ACCESS_KEY: ***
AWS_REGION: us-east-1
课后
class Post < ApplicationRecord
belongs_to :user, counter_cache: true
belongs_to :category
validates :title, :presence => true
validates :content, :presence => true
has_attached_file :thumbnail, styles: {
medium: '270x170#',
large: '560x280#',
large2: '540x340#'
}
# Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :thumbnail, :content_type => /\Aimage\/.*\Z/
end
【问题讨论】:
-
哪个环境给你这个错误?开发还是产品?
-
@TheOni 开发
标签: ruby-on-rails amazon-web-services amazon-s3 paperclip aws-sdk