title: 301 Moved Permanently after S3 uploading
body: <p>Im trying to upload images to S3 on Ruby on Rails using carrierwave and fog gems, images are uploaded correctly but when I try tu save the model containing information about the image that was just uploaded Im getting this error:</p>
  
  <pre><code>Excon::Errors::MovedPermanently in UserController#show
  app/models/user.rb:46:in `process_image_with_key'
  app/controllers/user_controller.rb:12:in `show'
  
  &lt;Excon::Response:0x007f97846a3c18 @body="&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;Error&gt;&lt;Code&gt;PermanentRedirect&lt;/Code&gt;&lt;Message&gt;The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.&lt;/Message&gt;
  </code></pre>
  
  <p>User model:</p>
  
  <pre><code>mount_uploader :image, AvatarUploader
  
  def image_name
    File.basename(image.path || image.filename) if image
  end
  
  def process_image_with_key( key )
    unless key.nil?
      self.key = key
      self.remote_image_url = self.image.direct_fog_url(with_path: true)
      self.save!
    end
  end
  </code></pre>
  
  <p>AvatarUploader:</p>
  
  <pre><code># encoding: utf-8
  
  class AvatarUploader &lt; CarrierWave::Uploader::Base
  
    include CarrierWaveDirect::Uploader
  
    include CarrierWave::RMagick
  
    # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
    include Sprockets::Helpers::RailsHelper
    include Sprockets::Helpers::IsolatedHelper
  
    include CarrierWave::MimeTypes
    process :set_content_type
  
    version :thumb do
      process resize_to_fill: [50, 50]
    end
  
  end
  </code></pre>
  
  <p>User controller</p>
  
  <pre><code>def show
    @user = User.find_by_id(params[:id])
    @user.process_image_with_key(params[:key])
    @uploader = User.new.image
    @uploader.success_action_redirect = user_url(@user.id)
  end
  </code></pre>
  
  <p>carriwerwave initializer</p>
  
  <pre><code>CarrierWave.configure do |config|
    config.fog_credentials = {
      :provider               =&gt; 'AWS',
      :aws_access_key_id      =&gt; ENV['AWS_ACCESS_KEY_ID'],
      :aws_secret_access_key  =&gt; ENV['AWS_SECRET_ACCESS_KEY'],
      :region                 =&gt; 'us-west-1'
    }
    config.fog_directory  = ENV['AWS_FILE_BUCKET']
    config.fog_attributes = {'Cache-Control'=&gt;'max-age=315576000'}
  end
  </code></pre>
  
  <p>gemfile</p>
  
  <pre><code>gem 'carrierwave'
  gem 'rmagick'
  gem 'fog'
  gem 'carrierwave_direct'
  </code></pre>