0

I'm trying to upload to S3 with Carrierwave and Fog-Aws, and I'm having an issue. For some reason, fog is trying to upload to my bucket at

https://{bucket-name}.s3.amazonaws.com

But, when I access a file directly from aws, the url format is like this:

https://s3-{region}.amazonaws.com/{bucket-name

Whenever I try to use the path that Fog is using, it gives me the following error:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

So my question is, is there a way to

A) Change the endpoint format on S3 to match what Fog is expecting it to be, or

B) Change a setting for Fog to use this different format instead?

For reference:

I'm using Carrierwave version 1.0, fog-aws version 0.11.0

Here's my carrierwave.rb file:

if Rails.env.test? or Rails.env.development?
  CarrierWave.configure do |config|
    config.storage = :file
    config.root = "#{Rails.root}/tmp"
    config.cache_dir = "#{Rails.root}/tmp/images"
  end
else
  CarrierWave.configure do |config|
    config.fog_provider = 'fog/aws'  
    config.fog_credentials = {
      :provider => 'AWS',
      :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
      :region => ENV['AWS_S3_REGION'],
      :endpoint => "https://s3-#{ENV['AWS_S3_REGION']}.amazonaws.com/#{ENV['AWS_S3_BUCKET_NAME']}"
    }
    config.storage = :fog
    config.fog_directory = ENV['AWS_S3_BUCKET_NAME']
    config.fog_public = false
  end
end
Charlie Pugh
  • 342
  • 2
  • 18

1 Answers1

0

I believe :region is the only setting you should need to change in this case. As long as it is set accurately (and isn't the default us-east-1 region) it should change the host as you desire.

That said, I would NOT expect to also need to change endpoint like this. It would be set if you needed to use CNAME stuff, which it doesn't sound like you need. Omitting this, while setting region, should hopefully get you what you are after.

geemus
  • 2,522
  • 16
  • 22