Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)

ASIHTTPRequest documentation

Last updated: 15th May 2011 (v1.8.1)

Rackspace Cloud Files support

New in v1.6 is complete support for the Rackspace Cloud Files storage and CDN service, contributed by Mike Mayo.

Most of these examples use synchronous requests for brevity, you should normally use a queue or [request startAsynchronous] to perform these operations asynchronously (more info..).

The classes

  • ASICloudFilesRequest
    An ASIHTTPRequest subclass that handles Rackspace Cloud authentication for you.
  • ASICloudFilesContainerRequest
    An ASICloudFilesRequest subclass that helps you retrieve info about your account and lists of containers. It also makes it easy to create and delete containers.
  • ASICloudFilesObjectRequest
    An ASICloudFilesRequest subclass that looks deeper into Cloud Files containers, providing directory listings, container info, and file uploads and downloads.
  • ASICloudFilesCDNRequest
    An ASICloudFilesRequest subclass that retrieves info on CDN-enabled containers and files and allows you to control CDN attributes on all of your Cloud Files containers.

GET an object

In this example, we'll get the object from Cloud Files that is stored at /container-name/path/to/the/object.

[ASICloudFilesRequest setUsername:@"my-username"];
[ASICloudFilesRequest setApiKey:@"my-api-key"];
[ASICloudFilesRequest authenticate];
 
ASICloudFilesObjectRequest *request = 
  [ASICloudFilesObjectRequest getObjectRequestWithContainer:@"container-name" 
  objectPath:@"/path/to/the/object"];
[request startSynchronous];
ASICloudFilesObject *object = [request object];

PUT an object

Since we have already authenticated, we don't need to do it again to upload a file.

NSData *data = [@"this is a test" dataUsingEncoding:NSUTF8StringEncoding];
 
ASICloudFilesObjectRequest *request = 
  [ASICloudFilesObjectRequest putObjectRequestWithContainer:@"container-name" 
  objectPath:@"my-file.txt" contentType:@"text/plain" objectData:data metadata:nil etag:nil];
[request startSynchronous];

DELETE an object

We won't set the access keys this time, because we've already set the shared ones.

ASICloudFilesObjectRequest *request = 
  [ASICloudFilesObjectRequest deleteObjectRequestWithContainer:@"container-name" 
  objectPath:@"my-file.txt"];
[request startSynchronous];

GET a list of objects

A list query is basically a GET request on a container. Cloud Files will return up to 10,000 objects in a single request. After that, another GET on the object is necessary to retrieve the fileʼs content.

ASICloudFilesObjectRequest *request = 
  [ASICloudFilesObjectRequest listRequestWithContainer:@"ASICloudFilesTest"];
[request startSynchronous];
NSArray *objects = [request objects];