Ruby on rails Aws::错误::PostsController中缺少凭据错误#使用回形针和Aws更新
我花了好几个小时研究这个问题,一直没能弄明白。我运行git clean,然后意识到我的s3.yml文件被删除了。我创建了新的密钥并将它们放在一个新的s3.yml文件中。我没有改变以前的任何事情,一切都很好。我错过了什么 我收到:Ruby on rails Aws::错误::PostsController中缺少凭据错误#使用回形针和Aws更新,ruby-on-rails,amazon-web-services,amazon-s3,paperclip,aws-sdk,Ruby On Rails,Amazon Web Services,Amazon S3,Paperclip,Aws Sdk,我花了好几个小时研究这个问题,一直没能弄明白。我运行git clean,然后意识到我的s3.yml文件被删除了。我创建了新的密钥并将它们放在一个新的s3.yml文件中。我没有改变以前的任何事情,一切都很好。我错过了什么 我收到:Aws::Errors::MissingCredentialsError(在未设置凭据的情况下无法签署请求): 这是我的密码: development.rb config.paperclip_defaults = { storage: :s3, s3_
Aws::Errors::MissingCredentialsError(在未设置凭据的情况下无法签署请求):
这是我的密码:
development.rb
config.paperclip_defaults = {
storage: :s3,
s3_region: 'us-east-1',
bucket:'mybucket',
s3_credentials: "#{Rails.root}/config/s3.yml"
}
production.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(具有新的访问密钥)
课后
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
class Posttrue
验证:content,:presence=>true
已附加\u文件:缩略图、样式:{
中等:“270x170#”,
大型:“560x280#”,
大2:'540x340#'
}
#验证附加图像是否为image/jpg、image/png等
验证附件内容类型:缩略图,:内容类型=>/\Aimage\/.\Z/
结束
当您在开发环境中遇到错误时,我认为错误是由于s3_凭据引起的:“{Rails.root}/config/s3.yml”
考虑到您发布的s3.yml,我认为s3\u凭证不会像您在生产环境中使用的那样填充json结构
我建议您像在生产环境中一样加载文件并填充json。哪个环境会给您带来这个错误?dev还是prod?@TheOni development我想这就是问题所在,但当我把它改成我在生产中拥有的东西时,我得到了“fetch”:找不到键:“S3\u BUCKET\u NAME”。我找到了答案!非常感谢你为我指明了正确的方向!:)我需要通过执行以下操作向终端中的环境变量添加值:export ENV_VARIABLE_NAME=“value”
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