title: Can CarrierWave upload to Amazon S3 but serve through CloudFront?
body: <p>I'm working on a small rails site which allows some users to upload images and others to see them. I started using CarrierWave with S3 as the storage medium and everything worked great but then I wanted to experiment with using CouldFront. I first added a <code>distribution</code> to my S3 bucket and then changed the CarrierWave configuration I was using to this: </p>
  
  <pre><code>CarrierWave.configure do |config|
    config.storage = :fog
    config.fog_credentials = {
      :provider               =&gt; 'AWS',                                         # required
      :aws_access_key_id      =&gt; ENV['S3_ACCESS_KEY_ID'],                       # required
      :aws_secret_access_key  =&gt; ENV['S3_SECRET_ACCESS_KEY'],                   # required
      :region                 =&gt; 'eu-west-1',
    }
    config.asset_host = 'http://static.my-domain.com/some-folder'
    config.fog_public     = true                                   # optional, defaults to    true
    config.fog_attributes = {'Cache-Control'=&gt;'max-age=315576000'}  # optional, defaults to {}
  end
  </code></pre>
  
  <p>I should mention that <code>http://static.my-domain.com</code> is a CNAME entry pointing to a CloudFront endpoint  (<code>some-id.cloudfront.net</code>). The result is that the pictures are shown correctly, URLs look like this: <code>http://static.my-domain.com/some-folder/uploads/gallery_image/attachment/161/large_image.jpg</code> but whenever I try to upload a photo or for that matter get the size of the uploaded attachment I get the following exception:</p>
  
  <pre><code>Excon::Errors::MovedPermanently: Expected(200) &lt;=&gt; Actual(301 Moved Permanently)
    response =&gt; #&lt;Excon::Response:0x007f61fc3d1548 @data={:body=&gt;"", 
    :headers=&gt;{"x-amz-request-id"=&gt;"some-id", "x-amz-id-2"=&gt;"some-id", 
    "Content-Type"=&gt;"application/xml", "Transfer-Encoding"=&gt;"chunked", 
    "Date"=&gt;"Mon, 31 Mar 2014 21:16:45 GMT", "Connection"=&gt;"close", "Server"=&gt;"AmazonS3"}, 
    :status=&gt;301, :remote_ip=&gt;"some-ip"}, @body="", @headers={"x-amz-request-id"=&gt;"some-id", 
    "x-amz-id-2"=&gt;"some-id", "Content-Type"=&gt;"application/xml", 
    "Transfer-Encoding"=&gt;"chunked", "Date"=&gt;"Mon, 31 Mar 2014 21:16:45 GMT", 
    "Connection"=&gt;"close", "Server"=&gt;"AmazonS3"}, @status=301, @remote_ip="some-ip"
  </code></pre>
  
  <p>Just to add some more info, I tried the following:</p>
  
  <ul>
  <li>removing the region entry</li>
  <li>using the CloudFront URL directly instead of the CNAME </li>
  <li>specifying the Amazon endpoint (<code>https://s3-eu-west1.amazonaws.com</code>)</li>
  </ul>
  
  <p>but all of them had no effect. </p>
  
  <p>Is there something I'm missing or is it that CarrierWave does not support this at this time?</p>