Search code examples
pythoncorsrackspace-cloud

Setting Access-Control-Allow-Origin (CORS) in the Rackspace Cloud Files Python API


I'm trying to enable CORS on my Rackspace Cloud Files. According to the docs, I can add the Access-Control-Allow-Origin header, but I don't see how to do that with the Python python-cloudfiles module API:

  conn = cloudfiles.get_connection('apaidnerd', 's3cr3t')
  container = conn.get_container('warez')

  obj = container.create_object('foo.png')
  obj.load_from_filename('/path/to/foo.png')

  # ...what's next?

Help?


Solution

  • Use the undocumented headers property of Object:

    obj.headers['Access-Control-Allow-Origin'] = '*'                                               
    obj.sync_metadata()