Rackspace Cloudfiles And Fog Cheatsheet05 Nov 2012
Here’s a quick cheat sheet for fog 1.7.0 to help myself out next time.
Everything starts with a storage instance
Retrieve Metadata for a Single Object
Use this to retrieve metadata about an object without downloading the content.
Retrieve Metadata for Multiple Objects
Use this to retrieve metadata about multiple object without downloading the content.
Or if you only want objects that start with a certain prefix.
Basic File Upload
Create a new object using data from a file.
Basic String Upload
Create a new object using data from a ruby string.
File Upload with Specific Headers
Create a new object and set some specific headers
Create a new object that rackspace will automatically delete after one day.
Deleting an Object
Iterating Over a Large Container
If you have a container with thousands of objects, fog can handle iterating over them all in a scalable way using each(). Behind the scenes it will retrieve file metadata in batches of 1000.
Note that map() will appear to work but only returns the first 1000 objects.
Expiring URLs provide a means to share otherwise private files with another user via a temporary HTTPS URL.
To begin using this feature, you will first need to set an account wide secret key. WARNING changing this secret will invalidate any previous expiring URLs.
Once the secret is set, you must to instantiate your storage object with an extra parameter.
Use this if you have an object already stored on cloud files and want to copy it to another object. This is particularly useful if the file is large as it avoids unnecessary downloading and uploading of the object data.
This is also useful if you want to change headers for an object, just use the same source and destination to “copy” the file onto itself.
There’s no facility to move an object - if you need to move one, just copy it then delete the original.