Windows Azure Storage - More Blobs!

So in my last blob related post, I setup the code so that I could simply call the Create Container action on the Blob Rest API.

My next step is to upload a picture file to that container. Now, you won't need to change much of the code, but as we are now starting to expand the number of actions we are performing, it starts to make sense to refactor the single implementation to cover multiple implementations.

For the next part of my application, I've encapsulated the basic functionality I need to deal with blobs into two classes, BlobRequest and BlobResponse.

Now the main crux of the BlobRequest class, that does the heavy lifting, is:

  • Setup the URI for the REST actions. This needs to also consider any query parameters such as acl for setting permissions on the container to either public or private or when providing metadata
  • Adding the Date header (x-ms-date)
  • Adding (and creating) the Authorization header
  • Adding the body for operations such as PUT blob

Now, some things to remember, you could almost call them gotchas:

  1. Storage REST operations are singular, so creating a public container for example is actually two steps:
    1. Create container
    2. Set Container ACL
  2. When writing to the HttpWebRequest body (through the GetRequestStream() method), do this after you create and add the Authorization header (which should also be the last step in creating the REST request) otherwise you will get funky errors like "Resource not found"

My next task is to continue building out the BlobRequest functionality and implement a WebRole for uploading and displaying my photos. :)

Technorati Tags: Windows Azure,Storage Service,Blobs