我设置了所有环境变量。我用heroku config
检查了它,但我仍然无法在开发环境中使用paperclip gem和aws s3保存图像并收到ArgumentError: missing required :bucket option
错误。我甚至尝试将AWS_BUCKET
更改为S3_BUCKET_NAME
,但仍然没有成功。我已经完成了每个堆栈溢出问题,我甚至可以找到与该主题相关的远程问题,但仍无法找到解决方案。
宝石
gem 'paperclip'
gem 'aws-sdk-v1'
gem 'aws-sdk', '> 2'
模型
has_attached_file :banner_image,
:storage => :s3,
:url =>':s3_domain_url',
:path => '/:class/:attachment/:id_partition/:style/:filename',
styles:
{
large: '600x600>',
medium: '300x300>',
thumb: '100x100>'
},
default_url: '/images/:style/missing.png',
:s3_credentials => Proc.new{|a| a.instance.s3_credentials }
def s3_credentials
{:bucket => Rails.application.secrets.aws_bucket, :access_key_id => Rails.application.secrets.aws_access_key_id, :secret_access_key => Rails.application.secrets.aws_secret_access_key}
end
validates_attachment_content_type :banner_image, content_type: /\Aimage\/.*\Z/
development.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_protocol => 'https',
:s3_region => Rails.application.secrets.aws_region,
:s3_credentials => {
:bucket => Rails.application.secrets.aws_bucket,
:access_key_id => Rails.application.secrets.aws_access_key_id,
:secret_access_key => Rails.application.secrets.aws_secret_access_key
}
}
secrets.rb
development:
admin_name: <%= ENV["ADMIN_NAME"] %>
admin_email: <%= ENV["ADMIN_EMAIL"] %>
admin_password: <%= ENV["ADMIN_PASSWORD"] %>
email_provider_username: <%= ENV["SENDGRID_USERNAME"] %>
email_provider_password: <%= ENV["SENDGRID_PASSWORD"] %>
domain_name: <%= ENV["DOMAIN_NAME"] %>
aws_access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
aws_secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
aws_bucket: <%= ENV["AWS_BUCKET"] %>
aws_region: <%= ENV["AWS_REGION"] %>
secret_key_base: hchwhc987h23y4bf93h4f928374h9f78h329487hf98723h4f789h234987hf89723h4f897h23498fh723487hf823974hf9872h34f7823489f
test:
domain_name: example.com
secret_key_base: hd78h2399d0a6315b087b3bebd35uhfhf8u3h4fh348fh92837h4f987h234f897h23487fh23897h4f98732h4f987h23498f7h324987fh239748f8237h4f987h3947hf
development_heroku:
admin_name: <%= ENV["ADMIN_NAME"] %>
admin_email: <%= ENV["ADMIN_EMAIL"] %>
admin_password: <%= ENV["ADMIN_PASSWORD"] %>
email_provider_username: <%= ENV["SENDGRID_USERNAME"] %>
email_provider_password: <%= ENV["SENDGRID_PASSWORD"] %>
domain_name: <%= ENV["DOMAIN_NAME"] %>
aws_access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
aws_secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
aws_bucket: <%= ENV["AWS_BUCKET"] %>
aws_region: <%= ENV["AWS_REGION"] %>
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
staging:
admin_name: <%= ENV["ADMIN_NAME"] %>
admin_email: <%= ENV["ADMIN_EMAIL"] %>
admin_password: <%= ENV["ADMIN_PASSWORD"] %>
email_provider_username: <%= ENV["SENDGRID_USERNAME"] %>
email_provider_password: <%= ENV["SENDGRID_PASSWORD"] %>
domain_name: <%= ENV["DOMAIN_NAME"] %>
aws_access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
aws_secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
aws_bucket: <%= ENV["AWS_BUCKET"] %>
aws_region: <%= ENV["AWS_REGION"] %>
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
admin_name: <%= ENV["ADMIN_NAME"] %>
admin_email: <%= ENV["ADMIN_EMAIL"] %>
admin_password: <%= ENV["ADMIN_PASSWORD"] %>
email_provider_username: <%= ENV["SENDGRID_USERNAME"] %>
email_provider_password: <%= ENV["SENDGRID_PASSWORD"] %>
domain_name: <%= ENV["DOMAIN_NAME"] %>
aws_access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
aws_secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
aws_bucket: <%= ENV["AWS_BUCKET"] %>
aws_region: <%= ENV["AWS_REGION"] %>
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
答案 0 :(得分:0)
那么,你有没有想过将环境变量添加到~/.bash_profile
export AWS_ACCESS_KEY_ID="KJAHSDH9HD0SAD89H"
export AWS_BUCKET="staging_value"
export AWS_SECRET_ACCESS_KEY="HASDF78H/JHIUDHSHHS8DH7USD7CH"
•然后运行source .bash_profile
•重启终端
这解决了我的问题。