title: CORS issue with a PreSigned S3 URL for file upload
body: <p>I try to upload files in an S3 bucket in eu-west-2 region:</p>
  
  <p>In the django-view i coded:</p>
  
  <pre><code>conn = boto.connect_s3(settings.AWS_ACCESS_KEY_ID,settings.AWS_SECRET_ACCESS_KEY,host=settings.AWS_S3_HOST)
       try:
          conn = boto.connect_s3(settings.AWS_ACCESS_KEY_ID,settings.AWS_SECRET_ACCESS_KEY,host=settings.AWS_S3_HOST)
      except:
          print "S3connection Failed"
      else:
          print "S3Connection OK"
  </code></pre>
  
  <p>Then i Generate the pre-signed url</p>
  
  <pre><code>try:
      S3url = conn.generate_url_sigv4(secondsPerDay, "PUT", bucket=settings.AWS_STORAGE_BUCKET_NAME, key=path, force_http=True)
  except:
      print "generate_url_sigv4 failed"
  else:
      print "generate_url_sigv4 OK"
      print S3url
  </code></pre>
  
  <p>and S3url is:
      S3url= <a href="https://MyBucketName.s3-eu-west-2.amazonaws.com/pathtofile/0.MOV?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Expires=86400&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Signature=AWSsignature&amp;X-Amz-Date=20170724T120524Z&amp;X-Amz-Credential=MyKey%2F20170724%2Feu-west-2%2Fs3%2Faws4_request" rel="nofollow noreferrer">https://MyBucketName.s3-eu-west-2.amazonaws.com/pathtofile/0.MOV?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Expires=86400&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Signature=AWSsignature&amp;X-Amz-Date=20170724T120524Z&amp;X-Amz-Credential=MyKey%2F20170724%2Feu-west-2%2Fs3%2Faws4_request</a> </p>
  
  <p>Using Curl i can upload a video file with :</p>
  
  <pre><code>curl -v -T "0.MOV" --header "Content-Type:binary/octet-stream" "https://MyBucketName.s3-eu-west-2.amazonaws.com/pathtofile/0.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Expires=86400&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Signature=AWSsignature&amp;X-Amz-Date=20170724T122024Z&amp;X-Amz-Credential=MyKey%2Feu-west-2%2Fs3%2Faws4_request"
  </code></pre>
  
  <p><strong>So for me the generation of pre-signed url in django/python is ok.</strong></p>
  
  <p>By the way thanks to <a href="https://stackoverflow.com/questions/30769301/how-to-properly-upload-an-object-to-aws-s3">How to properly upload an object to AWS S3?</a> contributors</p>
  
  <p>The problem comes when i try to use the presigned url through and ajax request. <strong>Google Chrome</strong> states:</p>
  
  <pre><code>Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8000' is therefore not allowed access. The response had HTTP status code 403.
  </code></pre>
  
  <p>I try many combinations of</p>
  
  <pre><code>settings = $.extend(true, {}, {
      xhr: function () {
          var xhrobj = $.ajaxSettings.xhr();
          return self._initXhr(xhrobj, previewId, self.getFileStack().length);
      },
      url:S3url,
      type: 'PUT',
      cache: false,
      processData: false,
      success: fnSuccess,
      complete: fnComplete,
      error: fnError,
      crossDomain: true,
      headers: {
              'Access-Control-Allow-Headers': '*',
              'Content-Type': 'binary/octet-stream',
          },
  }, self.ajaxSettings);
  
  self.ajaxRequests.push($.ajax(settings));
  </code></pre>
  
  <p>Apparently, the browser and the curl is blocking request to another server.
  The web page is coming from <a href="http://127.0.0.1:8000" rel="nofollow noreferrer">http://127.0.0.1:8000</a> and the request is towards s3-eu-west-2.amazonaws.com.</p>
  
  <p>Curl does not take this precaution.</p>
  
  <p>By the way, i configure the S3 bucket like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt;
  &lt;CORSRule&gt;
      &lt;AllowedOrigin&gt;*&lt;/AllowedOrigin&gt;
      &lt;AllowedMethod&gt;GET&lt;/AllowedMethod&gt;
      **&lt;AllowedMethod&gt;PUT&lt;/AllowedMethod&gt;**
      &lt;MaxAgeSeconds&gt;3000&lt;/MaxAgeSeconds&gt;
      &lt;AllowedHeader&gt;Authorization&lt;/AllowedHeader&gt;
  &lt;/CORSRule&gt;
  &lt;/CORSConfiguration&gt;
  </code></pre>
  
  <p>That's the defaut config except i add the <strong>/</strong> line.</p>
  
  <p>So how could i solve this CORS issue, what do i miss ?</p>
  
  <p>Thanks</p>