之前已经询问过这个错误,但我已经在这里尝试了所有的答案,但没有一个有效。
我正在尝试将AWS s3连接到rails:
我在这个问题的底部粘贴了错误。
carrierwave.rb:
declare -a values=($(sed 's/.*<\(.*\)>.*/\1/' input_file))
echo "${values[0]}" # 0xaaa
echo "${values[1]}" # 0xbbb
# ... If there are more lines in input_file then the array will be bigger ...
# ${values[2]} will contain next lValue
# ${values[3]} will contain next rValue
# ... and so on ...
我使用figaro为我的环境变量成功安装并创建了application.yml(注意哈希是掩盖密钥但在文件中是正确的):
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], # required
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], # required
region: ENV['AWS_REGION'], # optional, defaults to 'us-east-1'
}
config.fog_directory = 'discoveredfmyelpdemo' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
我不知道为什么会影响它,以防万一我会给你我的宝石和上传器相关的文件内容(我是ROR的新手)。
Avatar_Uploader.rb:
AWS_ACCESS_KEY_ID: "A########################SA"
AWS_SECRET_ACCESS_KEY: "ba####################st"
AWS_REGION: "Sydney"
development:
AWS_BUCKET: discoveredfmyelpdemo
production:
AWS_BUCKET: discoveredfmyelpdemo
的Gemfile:
class AvatarUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
这是完整的错误:
gem "fog-aws"
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
gem 'figaro', '1.0'
感谢您的帮助。
答案 0 :(得分:2)
application.yml
aws_access_key_id: "A########################SA"
aws_secret_access_key: "ba####################st"
aws_region: "Sydney"
development:
aws_bucket: discoveredfmyelpdemo
production:
aws_bucket: discoveredfmyelpdemo
并像这样访问ENV['aws_access_key_id']
您可以用小写字母尝试yml文件中的键吗?