Database Reference
In-Depth Information
11.4 Use of Blob Storage
Blob stands for “binary large object.” In Windows Azure, the Blob storage can be used to store
large amounts of unstructured data such as image iles. Windows Azure allows users to store as
much as 100 TB Blob data. he Blob storage service consists of a storage account, container, and
Blob. To store and access Blob data, the user needs to create a Blob storage account in Windows
Azure. A storage account can host many containers and one container can host many Blobs. he
binary iles will be stored in one of the Blobs. he Blob can be categorized into two types: block
Blob and page Blob. he size of a block Blob can be up to 200 GB. he size of a page Blob can be
up to 1 TB.
In the previous activity, you have created a Blob storage account when creating an account
for using the Windows Azure storage emulator. To connect the Blob storage service from an
application, you will irst need to establish the account by initiating an object of the type
CloudStorageAccount with the connection string to your Windows Azure account. Once the
connection is established, you will need to initiate an object of the CloudBlobClient type. his
object will be able to retrieve the references of containers and the Blobs stored in these contain-
ers. With the CloudBlobClient object, the user can also create containers if they do not already
exist.
To upload a ile to a speciic Blob, you will irst need to get the reference of the container that
contains the Blob. he default permission for a container is Private. For public access, you may
need PublicAccess. hrough the container, you will be able to get Blob's reference. With the refer-
ence of the container, you can also list the information about the Blobs hosted by the container
with the method ListBlobs. Once you have Blob's reference, you can then upload the iles to that
Blob with the UploadFromStream method. By using the reference of the Blob, you can download
the Blob with the DownloadToStream, DownloadToFile, DownloadByteArray, or DownloadText
methods to transfer the Blob contents to various types of local iles. With the Blob reference, you
can also delete the Blob with the Delete method.
To use the Blob storage service in our project, you need to declare the CloudBlobClient type
object for the class StudentClub in the Default.aspx.cs ile. You may also set the Boolean variable
storageInitialized to false control the initialization process.
//Declare the CloudBobClient type of the object.
private static bool storageInitialized = false;
private static CloudBlobClient blobStorage;
You also need to add the code in the initialization method to create a container and Blob.
//Create blob container for images.
//Do not use Upper case for container name.
blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference("m
emberphoto");
container.CreateIfNotExist();
//Change container permission to public access.
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
he code has been added to the Default.aspx.cs ile in Activity 11.1.
Search WWH ::




Custom Search