我正在尝试在rails应用程序中使用Paperclip和Amazon S3。奇怪的是,在将变量存储在environment.yml
之前,它才有效我收到错误
ArgumentError - 缺少必需:bucket选项:
这是我的环境开发:
AWS_ACCESS_KEY_ID: "myid"
AWS_SECRET_ACCESS_KEY: secretkey
AWS_BUCKET: elasticbeanstalk-us-west-1-299430007588.s3.amazonaws.com8
在config / environments / development.rb 中
config.paperclip_defaults = {
:storage => :s3
:s3_credentials => {
:bucket => ENV['AWS_BUCKET'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
然后在制作中
config.paperclip_defaults = {
:storage => :s3
:s3_credentials => {
:bucket => ENV['AWS_BUCKET'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
在我的食谱模型中
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
has_attached_file :download,
:storage => :s3,
:s3_credentials => Proc.new{|a| a.instance.s3_credentials }
def s3_credentials
{:bucket => ENV['AWS_BUCKET'], :access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']}
end
gemfile
gem "paperclip", "~> 4.3"
gem 'aws-sdk','< 2.0'
任何帮助都会很棒,我看到人们已经在询问并遵循了人们建议修复的内容,但它没有用。 在config / application.rb
中config.assets.version = '1.0'
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(env_file)
end