Wednesday 20 February 2013

Rackspace cloud files - symlinks / aliases



The requirement is to have multiple names to the same object. For starters, there is no inbuilt way to do aliases or multiple names to the same object. However, after some documentation trolling there is a way to achieve it, although it is not straightforward.

Cloud files offers large file (over 5G) support by allowing multiple segments to be uploaded and then a manifest that links the segments.

http://www.rackspace.com/blog/rackspace-cloud-files-now-supporting-extremely-large-file-sizes/

You can use this feature to sort of achieve symlinking/aliasing

Here's a small example

curl -D - \

     -H "X-Auth-Key: AUTH key" \

     -H "X-Auth-User: user" \

     https://lon.identity.api.rackspacecloud.com/v1.0



curl -X PUT -H 'X-Auth-Token: AUTH TOKEN' \

https://storage101.lon3.clouddrive.com/v1/<URL>/stream/imagedata1/1 --data-binary 'Image1'



curl -X PUT -H 'X-Auth-Token: AUTH TOKEN' \

-H 'X-Object-Manifest: sriramrajan.com/imagedata1/' \

https://storage101.lon3.clouddrive.com/v1/<URL>/stream/image1.txt --data-binary ''



curl -X PUT -H 'X-Auth-Token: AUTH TOKEN' \

-H 'X-Object-Manifest: sriramrajan.com/imagedata1/' \

https://storage101.lon3.clouddrive.com/v1/<URL>/stream/image2.txt --data-binary ''



This can be on CDN enabled containers as well and so once you do this, the following will be technically pointing to the same object.
<CDN URL>/image1.txt

<CDN URL>/image2.txt


2 comments:

  1. This is a very neat (ab)use of the API :) I just tried it with a few modifications, and it doesn't seem to need the source to be in its own "folder" (although, of course, those are actually fake in Cloud Files!) So, rather than putting "imagedata1/1", you can just put "image0.jpg".

    On checking the objects using cURL -I, there are a few quirks. Firstly, while the Content-Length: for both the real object and the link object are the same, the ETag is different, and -- more importantly -- the Content-Type is NOT set based on that of the real object (unsurprisingly). So, an explicit "Content-type:" header must be added when creating the link.

    Anyway, thanks for posting this... I'm now just trying to figure out if these empty files count towards the storage price... do you think metadata gets counted, or just the main data itself?

    ReplyDelete
  2. Good point on the folder. I did not test with that. Thanks.

    There is no additional charge for GET or PUT requests. Your charges will depend on size of the file and the bandwidth used in accessing them. Since the size is 0 here, any additional bandwidth charges will be minimal.

    ReplyDelete