In the previous post I have showed a couple basic PowerShell commands that are used to interact with Azure Blob Service. In this post I am going to show how to work with Azure Blob Service containers from code.
Refer to previous posts to get started with Azure Blob Service.
A container provides a grouping of a set of blobs. All blobs must be in a container. An account can contain an unlimited number of containers. A container can store an unlimited number of blobs. Note that the container name must be lowercase. Containers are created immediately beneath the storage account. It's not possible to nest one container beneath another.
There are two types of containers:
The only difference between them is that a blob stored in the root container may be addressed without referencing the root container name, so that a blob can be addressed at the top level of the storage account hierarchy.
The following code creates a root container:
var rootContainer = blobClient.GetRootContainerReference(); rootContainer.CreateIfNotExists();
To create a named container:
var container = blobClient.GetContainerReference("testcontainer"); container.CreateIfNotExists();
I already covered how CreateIfNotExists, Create, DeleteIfExists and Delete commands work for tables at Part 12: Azure Table + .NET - Basics. This methods work in a similar way for containers. The only difference is that you need to specify BlobContainerPublicAccessType when you create a container. It can be:
So you should use BlobContainerPublicAccessType.Blob for some static content that you want to share on your site.
In this post I have showed how to create the root container and a named container. In the next post I am going to show how to work with blobs inside a container.