Rails 4: Heroku + Paperclip + s3 not working in production

ぐ巨炮叔叔 提交于 2019-12-01 13:36:07

问题


so im following this tutorial: https://devcenter.heroku.com/articles/paperclip-s3

I manage to deploy it to Heroku and App is working in the development. The app is running in Heroku but when i try to upload photo. it gives me this page

We're sorry, but something went wrong.

I try to debug it by going to console and typing heroku logs it gives me the following error:

heroku[router]: at=info method=POST path="/friends" host=s3friends.herokuapp.com request_id=4173ed9e-ed69-492c-b1b9-d98227ca678c fwd="98.207.140.59" dyno=web.1 connect=9ms service=2668ms status=500 bytes=1754

Production.rb

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['S3_BUCKET_NAME'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
  }

gem file:

gem 'aws-sdk'
gem 'rails', '4.2.5'

group :production do
    gem 'pg'
end

I've also made sure that the credential on my heroku config match the credential on my s3.

any help would be greatly appreacted.


回答1:


Add region and s3_host_name.

config.paperclip_defaults = {
    storage: :s3,
    s3_credentials: {
      bucket: ENV["S3_BUCKET_NAME"],
      access_key_id: ENV["AWS_ACCESS_KEY_ID"],
      secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
      s3_region: ENV["S3_REGION"],
      s3_host_name: ENV["S3_HOST_NAME"]
    }

S3_REGION="eu-central-1" S3_HOST_NAME="s3.eu-central-1.amazonaws.com"

Regions and endpoints: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

Using gem "aws-sdk", "~> 2.0"




回答2:


For those facing the same problem, I solved this by renaming :bucket => ENV['S3_BUCKET_NAME'], to :bucket => ENV['AWS_BUCKET'],

and downgrading gem 'aws-sdk' to gem 'aws-sdk', '~> 1.61.0'

and it fix my problem.



来源:https://stackoverflow.com/questions/35098534/rails-4-heroku-paperclip-s3-not-working-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!