ruby-on-rails – Ruby on Rails: Error uploading images to Amazon S3 with paperclip and fog

Question:

I'm using the 'fog' and 'paperclip' gems to upload images to s3, but every time I request my API to save the image it throws me a warning in the terminal:

[fog] [WARNING] fog: followed redirect to s3-eu-west-1.amazonaws.com, connecting to the matching region will be more performant

and my model is configured like this:

has_attached_file :avatar,
  :storage => :fog,
  :fog_credentials => {
                        :provider                 => 'AWS',
                        :aws_access_key_id        => access_key_id,
                        :aws_secret_access_key    => secret_access_key,
                        :region                   => 'eu-west-1',
                        :path_style               => true
                      },
    :fog_directory => "bucket",
    :fog_region    => 'eu-west-1'

I don't know if the error is because I am sending a base64 image or some error in the amazon s3 configuration

Answer:

You must remove the option :fog_region , it already has it specified in :fog_credentials , with this it will stop showing the warnings.

example:

config.paperclip_defaults = {
          :storage => :fog,
          :fog_credentials => {
            :provider => "AWS",
            :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
            :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
            :region => 'eu-west-1',
          },
          :fog_directory => ENV["S3_BUCKET_NAME"]
       }
     end
Scroll to Top