In this article we are trying to create a blob in the
storage emulator. The same blob creation
can be done on storage account too.
Some Theories on Blob
represents Binary Large Object
can contain text and binary data
are required for storing Blobs
can be private and public
can have metadata
The storage account created should be having containers for
storing blobs. The containers can be
viewed as folders.
Eg: Documents, Images etc.
The private containers are private to the storage account
and only the account holder can access it.
The urls in public containers are accessible over the internet.
The Blob can have metadata as collection of key value
pair. We can store the information like
Author, Date, and Description etc. for the blob.
Advantages of Blob
The blob helps us to store image files, documents etc. which
are normally unstructured data. If the
same is stored in database, it results in performance problems.
Without a blob service, the manual programming requires much
effort to manage the large sized files.
The activities include:
a File/Folder infrastructure in the web application space
with multipart uploads for uploading large files
a database table for managing the metadata
the corresponding entities
with backup and restore of the large files involving high network traffics
Thanks to Microsoft, the blob service does all the things
for us at a lower cost.
Steps in creating
Following are the steps in creating a blob.
The first step (Create Storage Account) was already done
from our side and we need to proceed with the further steps to create the blob.
There are two ways of creating container and blob
Windows Azure Management Tool
In this article we are proceeding with the first way and the
second way will be discussed in another upcoming article.
Following are the steps involved in the creation of
container and blob.
Step 1: Create new
web azure project
Create a new Windows Azure project and add a web role into
it. The solution explorer would look
Step 2: Add
reference to library files
We need to add specific reference to the following Windows
Azure SDK dll file.
Files\Windows Azure SDK\v1.5\ref
Step 3: Create
Now open the code view of Default.aspx, place a label
control on it and enter the following code.
protected void Page_Load(object sender, EventArgs e)
CloudStorageAccount account =
CloudBlobClient client =
CloudBlob blob =
// show the blobs
Label1.Text = "Blobs inside container:
foreach (IListBlobItem item in
item.Container + " " + item.Parent.ToString() + "
container name as documents. We need to ensure the name should be
lowercase and additional restrictions. An invalid naming convention will throw
with message "One of the request inputs is out of range."
There are two methods in class CloudBlobContainer for
creating the container.
Using the CreateIfNotExist() method is advised as it won't
throw the exception if a container already exists with the given name.
Step 4: Create
the blob file
In the web role project add a file named File.txt with some text contents. Execute the application and you can see the
Note: The local Storage Emulator is used in the above code for creating the
container and blob. In the real scenario
of uploading to online storage account, we need to modify the line:
as shown below
In this article we have learned some information on blob,
container and how to create them programmatically. The associated source code can be used to
test blob creation in your local machine.