One of the key features of Windows Azure is that it
can scale with your application’s development and deployment. Thus, as
you add more data and deploy more services to Windows Azure, it grows
along with you, easing the burden of resource, service, and storage
usage on your local servers. Many organizations today must regularly
manage on-premises servers to ensure that space is not exceeded by large files.
Rather than chasing hardware limits, suppose that you could take a
portion of the binary files that are managed within an application and
move them off to the cloud; this could save you quite a bit of
file/archive management and make your life much easier. It would also
avoid potential downtime due to oversubscribed server capacity, which
eventually leads to software failures and end-user dissatisfaction.
Windows Azure has several constituent parts, one of which is BLOB storage. BLOB stands for binary large object and refers to the storage of binary data such as images, videos, and more. BLOB storage is one of three primary types of storage within Windows Azure; the others types are table storage (for non-relational data storage) and queue storage (for messaging). For more information on Windows Azure storage, go to http://www.microsoft.com/windowsazure/storage/default.aspx.
Windows Azure BLOB
storage is also a flexible cloud storage option that provides a set of
REST-based APIs. By using these APIs, you can interact with the
different Windows Azure storage services by using a standard HTTP
request. For example, the following REST URI queries BLOB storage and returns an XML feed of all of the images and image properties in the imagefiles BLOB container:
http://fabrikam.blob.core.windows.net/imagefiles?restype=container&comp=list
You can integrate with BLOB storage through different types of applications by using the core Windows Azure storage libraries (such as Microsoft.WindowsAzure.StorageClient.dll and Microsoft.WindowsAzure.DevelopmentStorage.Store.dll).
For example, you can interact with BLOB storage via a simple console
application, reading and writing data into the underlying BLOB
containers. You can also create web roles that provide a web-based user
interface to upload files to BLOB storage in Microsoft ASP.NET
applications. And you can create services or worker roles that also interact with BLOB storage. Creating applications that use Windows Azure BLOB storage is relatively straightforward and well documented.
At a high level, the underlying structure of Windows Azure BLOB storage includes three core resources:
An account For example, in the following URI, fabrikamlegal represents the account name: http://fabrikamlegal.blob.core.windows.net. (As the owner of the BLOB storage account, you will have an account key that enables you to access it.)
A container This is the artifact that stores the BLOBs.
The binary object This represents the underlying file that is stored in the container—for example, imgBoston.jpg.
Each of the above core
components is in some way expressed within the REST URI. For example,
using the information above, the URI to access the imgBoston.jpg BLOB would look like the following:
http://fabrikamlegal.blob.core.windows.net/mystuff/imgBoston.jpg
In this URI, fabrikamlegal is the account name, mystuff is the container, and imgBoston.jpg is the BLOB.
Note:
More Info For more information about the Windows Azure BLOB REST API, see “Blob Service API” at http://msdn.microsoft.com/en-us/library/dd135733.aspx.
Within BLOB storage, you’re not constrained to the number
of BLOBs in a container. For example, you could have one or more BLOBs
per container. You can also have many containers within an account; Figure 1 shows one account with three containers, each containing a set of binary files.
When you translate Figure 1
into code, you’ll find that things look a little more complex than this
conceptual representation might suggest. For example, if you look at
the code snippet that follows, you’ll see that your account information
can be derived programmatically from your data connection string settings (DataConnectionString), which is a resource that is automatically created for you when you create the cloud project:
...
//Set up and create BLOB storage containers.
azureStorageAcct =
CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
azureBlobClient = azureStorageAcct.CreateCloudBlobClient();
//Create a new container for the images to upload.
azureBlobContainer = azureBlobClient.GetContainerReference("imagefiles");
azureBlobContainer.CreateIfNotExist();
//Set the permissions for the image BLOB container.
azureBlobPermissions = new BlobContainerPermissions();
azureBlobPermissions.PublicAccess = BlobContainerPublicAccessType.Container;
azureBlobContainer.SetPermissions(azureBlobPermissions);
...
You’re not necessarily relegated to using the DataConnectionString
property; you can, in some cases, use other methods to map the
connection information needed to interact with BLOB storage through
other means, such as parsing resource strings. You also see from the code snippet that you can create a new container—in this case, one called imagefiles. You might notice that this code first called the GetContainerReference method, which is then followed by the CreateIfNotExist method. The latter will create a new container called imagefiles
if that container does not already exist within the BLOB storage. The
final item in the code snippet is the setting of the permissions. Windows
Azure has a very flexible system of permissions, enabling you to assign
discrete levels of permission for the container or for the BLOB within
the container—or even create a sharable key that can expose BLOBs or
containers. In the code just shown, you’re assessing public
access to the BLOB storage.
It was mentioned earlier that
REST is the primary way of integrating with BLOB storage, and this is
absolutely true. However, as you can see from the code just examined,
you can also use Microsoft .NET Framework libraries. (The .NET Framework libraries are simply .NET wrappers for the REST-based API.)
To create BLOB storage, you
need to ensure that you have created a new storage account in your
Windows Azure developer portal. After you have created this account, you
can then use it for BLOB storage. To create a new storage account,
simply navigate to your Windows Azure developer portal, click Hosted
Services | Storage Accounts & CDN, click Storage Accounts, and then
select New Storage Account in the main UI ribbon. Windows Azure will
prompt you to provide a subscription option, account name, and region,
and then you can click OK to create the new storage account.