Home | Blog | Screencasts | Projects
# Wednesday, November 05, 2008

Last night I started having a bit of a play with the Azure blob storage system. The first thing to do is install the SDK and get the development storage and development fabric setup.

The SDK gives you the ability to go File –> New –> Cloud Project, I selected the web role for my demo (the other options include a stand alone worker, or combined web and worker roles).

From here I included the StorageClient project from the Azure SDK samples, this has a bunch of wrapper classes that are helpful.

Then I added some appSettings entries that contain URL’s for the development tools:

 

   1: <appSettings>
   2:   <add key = "AccountName" value="devstoreaccount1"/>
   3:   <add key = "AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="/>
   4:   <add key="BlobStorageEndpoint" value="http://127.0.0.1:10000/"/>
   5:   <add key="QueueStorageEndpoint" value="http://127.0.0.1:10001"/>
   6:   <add key="TableStorageEndpoint" value="http://127.0.0.1:10002"/>
   7: </appSettings>

 

The only thing that I was interested in was putting stuff into the blob storage, so I put together a simple asp.net page that contained an upload file control and a button.

I wired up the button event with the following code:

 

   1: protected void btnTest_Click(object sender, EventArgs e)
   2: {
   3:     StorageAccountInfo blobAccount = StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration();
   4:     
   5:     BlobStorage blobStorage = BlobStorage.Create(blobAccount);
   6:     blobStorage.RetryPolicy = RetryPolicies.RetryN(1, TimeSpan.FromMilliseconds(100));
   7:     
   8:     BlobContainer container = blobStorage.GetBlobContainer(Guid.NewGuid().ToString());
   9:  
  10:     NameValueCollection containerMetadata = new NameValueCollection();
  11:     containerMetadata.Add("Name", "TestContainer");
  12:     container.CreateContainer(containerMetadata, ContainerAccessControl.Public);
  13:  
  14:     string blobName = Path.GetFileName(testFile.PostedFile.FileName);           
  15:     BlobProperties properties = new BlobProperties(blobName);
  16:     container.CreateBlob(properties, new BlobContents(testFile.PostedFile.InputStream), true);
  17: }

 

To prove that the uploaded file was inserted into the blob, I used the CloudDrive project that is also provided by the Azure SDK, this project provides some PowerShell magic to allow you to mount the blob storage as a drive (the drive is blob:) so in the command window I could do the following:

 

image

 

This just lists all the containers that have been created and then the blob’s that live inside those containers.

 

Now the interesting part is that we can use the browser to also view our blob:

image

The MSDN pages give us the details, but basically you browse to http://127.0.0.1/devstoreaccount/<container>/<blobname>

Of course you’ll only be able to browse like this unauthenticated if your container is publically viewable, these attributes were set above with the ContainerAccessControl.Public parameter on the CreateContainer method call.

Wednesday, November 05, 2008 8:31:00 PM (E. Australia Standard Time, UTC+10:00)  #    Comments [0] - Trackback
Azure | code
Statistics
Total Posts: 134
This Year: 0
This Month: 0
This Week: 0
Comments: 20