Vee
Vee

Reputation: 1841

Carrierwave - configuring for Amazon S3

I have a Rails 4 application and am trying to configure Carrierwave and Fog to store uploaded files on Amazon S3 but I keep getting the following error:

Expected(200) <=> Actual(301 Moved Permanently) excon.error.response :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><RequestId>3C27ACF693820E4E</RequestId><Bucket>bucket_name</Bucket><HostId>8hnHAWoVEgsGkSyclME99rPTq5UHuSt6ZQ/ezmCRcuK+JUGWsSeI4FvcC2A5cym7</HostId><Endpoint>s3.amazonaws.com</Endpoint></Error>" :headers => { "Content-Type" => "application/xml" "Date" => "Wed, 03 Sep 2014 06:59:16 GMT" "Server" => "AmazonS3" "x-amz-id-2" => "8hnHAWoVEgsGkSyclME99rPTq5UHuSt6ZQ/ezmCRcuK+JUGWsSeI4FvcC2A5cym7" "x-amz-request-id" => "3C27ACF693820E4E" } :local_address => "10.0.0.9" :local_port => 54480 :remote_ip => "176.32.114.26" :status => 301

config/initializers/carrierwave.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
  :provider               => 'AWS',
  :aws_access_key_id      => 'XXXXXXXXXXXXXXXXXXXX',
  :aws_secret_access_key  => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  :region                 => 'us-east-1'
}
config.fog_directory  = 'bucket_name'
config.fog_public     = false
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end

I've also tried removing the :region parameter (along with the preceding comma) but that doesn't seem to work either. I've checked the bucket region and it is listed as "US Standard" but if I look at endpoint, Amazon lists that bucket as us-east-1. Regardless, I've tried assigning both of those values to :region and neither worked.

Can somebody help me figure out what I'm doing wrong?

Upvotes: 1

Views: 416

Answers (1)

Vee
Vee

Reputation: 1841

In case this might help somebody save a few hours of their life, the solution turned out to be that I just needed to restart the server after modifying the file.

Upvotes: 1

Related Questions