Microsoft has been promoting Azure (their version of cloud) a lot over the past few years and I finally got around to taking a look into their storage. I specifically focused on Blob storage which is designed to store binary data in a fairly flat structure. Once I installed the SDK and tools for VS 2010 (located here) I used this quick start guide as an example to create a test application for uploading files into Blob storage.
When developing an application, the Azure team provided the ability to point to your own DevelopmentStorageAccount which allows you use a Storage Emulator to develop your applications against instead of requiring you to pay for an Azure account just to get started. By default this emulator points to a Sql 2008 Express instance, but I have a full version of Sql 2008 so in order to get it to work I needed to run the DSInit command-line tool. I used this page to accomplish the task.
I created a really simple WPF application that allowed me to switch between 3 different BlobContainers, upload a file to the selected container, view all files in the container, and clear the container.
Both uploading a file and clearing the container were pretty simple. I complicated uploading a bit by getting each blob by a new Guid so that I never overwrote a file, but when listing all the files in the container I wanted an easy way to just display the filename and not have to parse the uri of the returned objects. So right before uploading I store the filename in the Metadata collection of the blob. Then when I wanted to list the blob I thought it would be as easy as calling ListBlobs on the container. This did get me each blob but the Metadata never had any values stored in it. Turns out that the ListBlobs call won’t include the Metadata by default in order to decrease size and increase the response speed. To include the Metadata the ListBlobs method requires you to create a BlobRequestOptions that specifies the Metadata as needing to be included.
var blobItems = blobContainer.ListBlobs(new BlobRequestOptions { BlobListingDetails = BlobListingDetails.Metadata }).OfType<CloudBlockBlob>().ToList();
Once I included that in the call, the filename value was in the Metadata collection and I was able to bind straight to it in XAML.
<ListBox x:Name="ExistingFilesList"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Metadata[filename]}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
This is just the tip of the iceberg, but it is nice to see that I was able to get some decent functionality in a fairly short amount of time.
If you want to take a look at my solution here you go: TestingAzureStorage
Pingback: InterKnowlogy Blogs » Blog Archive » Stream HTML5 Video from Azure Blob Storage