Start Developing on Azure… BLOBing

Posted: June 18, 2011 in Uncategorized, Windows Azure

First Step to use the BLOB

“Pay as you go” è this is one of the advantages of Cloud Computing. Speaking of Windows Azure as Microsoft Platform for Cloud Computing, it offers developers different types of storage one of them is the BLOB. It stands for Binary Large Object.

It is used for uploading any type of file to the Cloud like a text file, a picture or even a movie. The blob’s size can be terabytes and can be divided in Blocks or BlobPages which I am going to discuss in later blogs. I just wanted to show you in this blog who to work with Azure using blob storage especially it only cost you 0.15$/month for each GB (prices may vary from continent to another) plus the number of transactions which is equal to 0.01/month for each 10K transactions made.

To Begin in the Technical part we have to understand the main things that must exist to start using the BLOB storage.

Let’s simply imagine it as something like your desktop. Your windows on your desktop may have several accounts where each one of them is only allowed to access only certain number of files. This is nearly like the windows Azure Storage you do have some files on it which we call the blobs. You must have the account where you have put the blob storage.

So what’s about the container? The containers are only something virtual. For example your hard disk is divided into a certain number of partitions on your desktop. Each partition has a name (C, D ….). On Azure it is also nearly the same the container are the virtual place where you put the blobs.

For each account you make, you can have any number of containers and for each container any number of Blobs which size can be Terabytes.

First you have to set the connection string with which you are going to access the account like the following:

In the following code you will see how to create the account, container and to upload the blob:

public void uploadfile()
{
//creating the account and the cloud blob client

//sometimes you can find them separated the account 

//is created in a command and the cloudblob in another one

var account = CloudStorageAccount.FromConfigurationSetting(“DataConnectionString”).CreateCloudBlobClient();

//getting a reference for the blob so you can access it

var blob = account.GetBlobReference(“BlobAdress”);
try
{
//uploading the data required in the blob
//there are several overloaded method where you
//can upload different types of files in it
blob.UploadFile(“”);
}
catch (StorageException ex)
{
if (ex.ErrorCode == StorageErrorCode.ContainerNotFound || ex.ErrorCode == StorageErrorCode.BlobNotFound)
{
//getting a container reference
//you can access the container from other applications
//with the same account and the contaienr’s URI
var container = account.GetContainerReference(“ContainerName”);
//creating the container if it didnt already exists
container.CreateIfNotExist();

var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(permissions);
}
else
{
throw;
}
}
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s