title: Rails Carrier Wave and JQuery Uploader to Amazon S3
body: <p>I am trying to implement the multiple uploading to Amazon S3 <a href="https://github.com/jnicklas/carrierwave/blob/master/README.md" rel="nofollow noreferrer">https://github.com/jnicklas/carrierwave/blob/master/README.md</a> (under Using Amazon S3)</p>
  
  <p>But I got an error inside the log file:</p>
  
  <pre><code>Started POST "/images?project_id=18" for 124.106.90.29 at Wed Dec 14 19:11:47 -0600 2011
    Processing by ImagesController#create as JS
    Parameters: {"project_id"=&gt;"18", "authenticity_token"=&gt;"9z0CzTtMwxgfdsyFLCNzx44qqRDT8F7+6F/RsVzUe4=", "utf8"=&gt;"✓", "image"=&gt;{"carimage"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x6eab8de86708 @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"image[carimage]\"; filename=\"stroke_holding.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#&lt;File:/tmp/RackMultipart20111214-5354-1b4qtl7-0&gt;, @original_filename="stroke_holding.jpg"&gt;, "project_id"=&gt;"18"}}
    [1m[35mProject Load (0.2ms)[0m  SELECT `projects`.* FROM `projects` WHERE `projects`.`id` = 18 LIMIT 1
    [1m[36m (0.1ms)[0m  [1mBEGIN[0m
    [1m[35mSQL (1.2ms)[0m  INSERT INTO `images` (`caption`, `carimage`, `created_at`, `proj_photo_content_type`, `proj_photo_file_name`, `proj_photo_file_size`, `proj_photo_updated_at`, `project_id`, `updated_at`) VALUES (NULL, 'stroke_holding.jpg', '2011-12-15 01:11:48', NULL, NULL, NULL, NULL, 18, '2011-12-15 01:11:48')
    [1m[36m (1.7ms)[0m  [1mROLLBACK[0m
  Completed 500 Internal Server Error in 2635ms
  
  Excon::Errors::MovedPermanently (Expected(200) &lt;=&gt; Actual(301 Moved Permanently)
    request =&gt; {:port=&gt;"443", :method=&gt;"PUT", :idempotent=&gt;true, :body=&gt;#&lt;File:/home/ngtv2/activedesigns/public/uploads/tmp/20111214-1911-5354-1557/stroke_holding.jpg&gt;, :headers=&gt;{"Authorization"=&gt;"AWS XXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXX/XXXXXXXXXXXXXXXXXXX=", "x-amz-acl"=&gt;"public-read", "Date"=&gt;"Thu, 15 Dec 2011 01:11:48 +0000", "Content-Type"=&gt;"image/jpeg", "Content-Length"=&gt;64387, "Host"=&gt;"sample.s3-eu-west-1.amazonaws.com:443"}, :host=&gt;"sample.s3-eu-west-1.amazonaws.com", :query=&gt;nil, :connect_timeout=&gt;60, :expects=&gt;200, :read_timeout=&gt;60, :scheme=&gt;"https", :write_timeout=&gt;60, :path=&gt;"/stroke_holding.jpg", :mock=&gt;nil}
    response =&gt; #&lt;Excon::Response:0x6eab8c663f18 @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;&lt;RequestId&gt;2990AE131EF6DCE2&lt;/RequestId&gt;&lt;Bucket&gt;sample&lt;/Bucket&gt;&lt;HostId&gt;q+XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;/HostId&gt;&lt;Endpoint&gt;s3.amazonaws.com&lt;/Endpoint&gt;&lt;/Error&gt;", @status=301, @headers={"x-amz-id-2"=&gt;"q+XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXX", "Transfer-Encoding"=&gt;"chunked", "Date"=&gt;"Thu, 15 Dec 2011 01:11:49 GMT", "Content-Type"=&gt;"application/xml", "x-amz-request-id"=&gt;"2990AE131EF6DCE2", "Server"=&gt;"AmazonS3", "Connection"=&gt;"close"}&gt;):
    app/controllers/images_controller.rb:37:in `create'
  
  Rendered vendor/bundle/ruby/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
  Rendered vendor/bundle/ruby/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered vendor/bundle/ruby/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.4ms)
  </code></pre>
  
  <p>Here is my line 37 in images controller:</p>
  
  <pre><code>def create
    @image = Image.new(params[:image])
    if @image.save &lt;--------line 37
      render :json =&gt; [@image.to_jq_upload].to_json
    end
  end
  </code></pre>
  
  <p>I also get something like this in error console:</p>
  
  <p>Error: not well-formed
  Source File: <a href="https://s3-console-us-standard.console.aws.amazon.com/DeliverHttp" rel="nofollow noreferrer">https://s3-console-us-standard.console.aws.amazon.com/DeliverHttp</a>
  Line: 1, Column: 1
  Source Code:
  {</p>
  
  <p><img src="https://i.stack.imgur.com/g0hd9.png" alt="enter image description here"></p>
  
  <p>config/initializers/currierwave.rb</p>
  
  <pre><code>CarrierWave.configure do |config|
      config.fog_credentials = {
          :provider               =&gt; 'AWS', 
          :aws_access_key_id      =&gt; 'XXXXXXXXXXXXXXXXXXX', 
          :aws_secret_access_key  =&gt; 'XXXXXXXXXXXXXXXXXXX', 
          :region                 =&gt; 'eu-west-1'  
      }
      config.fog_directory  = 'sample'
      config.s3_bucket = "XXXXXXXXXX"
  end 
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/fGZTz.png" alt="enter image description here"></p>