2016-09-29 70 views
0

我有我所有的環境變量設置。我用heroku config進行了檢查,但仍然無法在開發環境中使用回形針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

將所有這些ENV密鑰添加到secrets.yml中似乎有很多重複。它還引入了一個錯誤和間接的來源,因爲你不應該將secrets.yml檢查到git中。我只是直接從初始值設定項中使用ENV.fetch(「SOME_KEY」)。 – max

回答

0

那麼,你有沒有想過到環境變量添加到您的~/.bash_profile

export AWS_ACCESS_KEY_ID="KJAHSDH9HD0SAD89H" 
export AWS_BUCKET="staging_value" 
export AWS_SECRET_ACCESS_KEY="HASDF78H/JHIUDHSHHS8DH7USD7CH" 

•然後運行source .bash_profile

•重新啓動終端

這解決了這個問題對我來說。

相關問題