2

Everything is working as expected locally. Once I push to heroku I can no longer upload images.

The error code I get from heroku logs is: Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)

The XML response contains: <Code>AccessDenied</Code><Message>Access Denied</Message>

My fog.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => ENV["ACCESS_KEY_ID"],
    :aws_secret_access_key  => ENV["SECRET_ACCESS_KEY"]
    #:region                 => 'eu-west-1'
  }

  #Required for Heroku
  config.cache_dir = "#{Rails.root}/tmp/uploads"

  config.fog_directory = ENV["BUCKET_NAME"]

end

My Uploader:

class ImageUploader < CarrierWave::Uploader::Base
    storage :fog
    def store_dir 
        "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
end

Heroku has the correct environment variables - I used the figaro gem. I also set them manually after I got the 403 the first few times to make sure figaro had no errors.

I thought this may be a problem with the region but my bucket is US and carrierwave documentation says the default is us-east-1

What is causing the issue on Heroku but not locally?

4

1 回答 1

2

禁止可能意味着配置的目录(而不是其他凭据)存在问题。BUCKET_NAME您是否在本地和 Heroku 上使用相同的值?我知道我当然尝试过使用我尚未创建的不同存储桶的东西(这也可能出现此错误)。因此,检查值是您所期望的(并且存储桶已经存在)是一个很好的起点。如果这不能为您解决问题,当然很乐意讨论并继续提供帮助。

于 2013-08-23T18:47:37.930 回答