2

I need to upload a file using AJAX to an Openstack Swift instance. In order to avoid sharing my auth token, I am using the form post middleware. It works when I do the upload from a normal html form, but when I try to make it from javascript using formdata I get the obvious error in the javascript console Cross origin request blocked: same origin policy disallows reading the remote resource in http://localhost:7000/v1/AUTH_container/container/files (reason: CORS header 'Access-Control-Allow-Origin' not present).

My container metadata is:

< HTTP/1.1 204 No Content
< Content-Length: 0
< X-Container-Object-Count: 44
< X-Storage-Policy: gold
< Accept-Ranges: bytes
< X-Container-Meta-Access-Control-Expose-Headers: Access-Control-Allow-Origin
< X-Container-Meta-Temp-Url-Key: changeme
< X-Container-Meta-Temp-Url-Key-2: changeme
< X-Container-Meta-Access-Control-Allow-Origin: http://localhost:8080
< X-Container-Bytes-Used: 10788833

So, the Access-control-allow-origin is set and, in fact, it is being sent when I try to access the resource by authenticating the request with X-Auth-Token header. However, when I authenticate the request using form post middleware the headers of the response are:

Connection: keep-alive
Content-Length: 46
Content-Type: text/plain
Date: Thu, 24 Dec 2015 11:05:49 GMT
x-trans-id: tx558c6847052542399b9ec-00567bd18d

and no Access-control-allow-origin header is present (making the request fail).

Is CORS feature in Openstack Swift not compatible with form post middleware, or am I missing something here?

joanlofe
  • 3,360
  • 2
  • 26
  • 44

0 Answers0