rackspace / php-opencloud

The PHP SDK for OpenStack clouds
developer.rackspace.com
Other
451 stars 249 forks source link

saveMetadata doesn't seem to work with Access-Control-Allow-Origin header #692

Closed ronnieschuurbiers closed 8 years ago

ronnieschuurbiers commented 8 years ago

I'm trying to upload a file from a website directly to Rackspace File Cloud with JavaScript so I'm not using my own servers bandwidth. I'm using this JavaScript code (https://developer.rackspace.com/blog/upload-files-directly-to-rackspace-cloud-files-from-the-browser/) with this PHP code (https://gist.github.com/jpilcher/923b823a9c6816250c56). In the browser console it says CORS-header ‘Access-Control-Allow-Origin’ is missing. The saveMetadata doesn't seem to do anything. If I look at the headers of the response of the OPTIONS request, indeed the header is missing. How can I get this to work?

I also tried setMetadata, on both the container and the object, but that doesn't work either.

jamiehannaford commented 8 years ago

Try this instead:

$container->saveMetadata(['Access-Control-Allow-Origin' => 'foo.com'], false);

Note the second arg.

ronnieschuurbiers commented 8 years ago

That didn't work either, but you got me on the right track so thanks anyway :) Apparently this works:

$result = $container->saveMetadata(array( 'X-Container-Meta-Access-Control-Allow-Origin' => '*', ), false);

jamiehannaford commented 8 years ago

Glad you sorted it out!