howto: Basic setup of carrierwave [Heroku and S3]

人走茶凉 提交于 2019-12-03 16:09:37

OK, here's an idea. CarrierWave still includes an S3 adapter for backward compatibility that uses fog underneath, which I personally use instead of :fog. In theory, there should be no difference between the two, but I think it's worth a shot. Here's my CarrierWave initializer from a live application running on Heroku:

CarrierWave.configure do |config|
  if Rails.env.production?
    config.root = Rails.root.join('tmp')
    config.cache_dir = 'carrierwave'

    config.storage = :s3
    config.s3_access_key_id = ENV['S3_KEY']
    config.s3_secret_access_key = ENV['S3_SECRET']
    config.s3_bucket = ENV['S3_BUCKET']
  else
    config.storage = :file
  end
end

The first two lines (config.root and config.cache_dir) are there to work around Heroku's read-only filesystem, which should have nothing to do with your problem.

One issue might be

config.fog_host       = 'http://www.example.com'

If you use this setting, you probably need a real host there. Supposedly you can comment that line out, although I've seen it highly recommended.

And I assume you set your ENV variables on Heroku?

heroku config:add S3_K=[my_s3_key] S3_SCRT=[my_s3_secret] S3_RG=[us-east-1]S3_BUCKET=[my_bucket_name]

I used pretty much the same setup. Mine didn't work, but I think I got a step or two further:

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