2

So, here's what I'm doing with the API:

  1. Auth (to get token and publicUrl for the particular region I need from the "object-store")

  2. Use the publicUrl from the endpoint like so to get a list of files: GET [publicUrl]/[container] This returns an array where each item (object) looks like the following:

    ( [hash] => 7213ee9a7d9dc119d2921a40e899ec5e [last_modified] => 2015-12-29T02:46:08.400490 [bytes] => 1 [name] => Some type of file name.jpg [content_type] => application/postscript )

Now, how do I build the url to do a GET on the item (object)? I've tried the following:

[publicUrl]/[container]/[hash] [publicUrl]/[container]/urlencoded([name])

among other things that don't make sense, but I tried anyway.

Any thoughts/help would be appreciated!

1
  • What language are you using? Are you using an SDK or using the API directly? Dec 29, 2015 at 15:26

1 Answer 1

3

If you are using a Rackspace SDK, you can skip building the URLs yourself.

Here is the documentation for retrieving a Cloud Files object using a public URL. The object URL is the combination of the public URL of the container (found in the X-Cdn-Uri response header) with the object name appended.

For example, for a container named 'foo', send an authenticated HEAD request to the API:

HEAD {cloudFilesEndpoint}/foo

In the response, the container's public URL is in the 'X-Cdn-Uri' header:

HTTP/1.1 204 No Content
X-Cdn-Ssl-Uri: https://83c49b9a2f7ad18250b3-346eb45fd42c58ca13011d659bfc1ac1.ssl.cf0.rackcdn.com
X-Ttl: 259200
X-Cdn-Uri: http://081e40d3ee1cec5f77bf-346eb45fd42c58ca13011d659bfc1ac1.r49.cf0.rackcdn.com
X-Cdn-Enabled: True
X-Log-Retention: False
X-Cdn-Streaming-Uri: http://084cc2790632ccee0a12-346eb45fd42c58ca13011d659bfc1ac1.r49.stream.cf0.rackcdn.com
X-Trans-Id: tx82a6752e00424edb9c46fa2573132e2c
Content-Length: 0

Now, for an object named 'styles/site.css', append that name to the public URL, resulting in the following URL:

http://081e40d3ee1cec5f77bf-346eb45fd42c58ca13011d659bfc1ac1.r49.cf0.rackcdn.com/styles/site.css
5
  • Thank you for the response. Is this the same for containers that are not CDN enabled?
    – Mr Mikkél
    Dec 29, 2015 at 19:38
  • If you want the object to be publicly accessible, then the container must be CDN enabled. Objects in private containers can only be accessed with an authenticated GET request. Dec 29, 2015 at 21:29
  • So, I am authenticating using the apikey, and sending the token in the subsequent requests..
    – Mr Mikkél
    Dec 30, 2015 at 6:39
  • Yes, if you don't make the container public by enabling CDN, then you must authenticate and use a token to retrieve objects. Did my answer work for you or are you still having trouble? Dec 31, 2015 at 17:37
  • It turned out that the url wasn't being returned in a HEAD request for me. I ended up figuring out that I was doing it right to begin with, but I wasn't url-encoding the file name properly (it was encoding spaces as "+" symbols instead of "%20"). I appreciated your response, as it helped my keep troubleshooting and get to the answer!
    – Mr Mikkél
    Dec 31, 2015 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.