Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a sub container in azure storage location

How can I create a sub container in the azure storage location?

like image 347
subramani Avatar asked Jul 06 '10 06:07

subramani


People also ask

How many containers can you have in Azure storage?

It is my understanding that an Azure Storage account can have unlimited containers. On this page it specifies: For a storage account, the maximum number of containers with locked time-based immutable policies is 10,000.

How do you make a CloudBlobContainer?

CloudBlobContainer container = new CloudBlobContainer("https://mystore.blob.core.windows.net/" + subDomain); This just creates an instance of CloudBlobContainer object. To create a container in your storage account, you would need to call CreateIfNotExists or Create function on this object.

How do I create a container in Azure Command Line?

To create a container instance with the Azure CLI, provide a resource group name, container instance name, and Docker container image to the az container create command. In this quickstart, you use the public mcr.microsoft.com/azuredocs/aci-helloworld image.


2 Answers

Windows Azure doesn't provide the concept of heirarchical containers, but it does provide a mechanism to traverse heirarchy by convention and API. All containers are stored at the same level. You can gain simliar functionality by using naming conventions for your blob names.

For instance, you may create a container named "content" and create blobs with the following names in that container:

content/blue/images/logo.jpg content/blue/images/icon-start.jpg content/blue/images/icon-stop.jpg  content/red/images/logo.jpg content/red/images/icon-start.jpg content/red/images/icon-stop.jpg 

Note that these blobs are a flat list against your "content" container. That said, using the "/" as a conventional delimiter, provides you with the functionality to traverse these in a heirarchical fashion.

protected IEnumerable<IListBlobItem>            GetDirectoryList(string directoryName, string subDirectoryName) {     CloudStorageAccount account =         CloudStorageAccount.FromConfigurationSetting("DataConnectionString");     CloudBlobClient client =          account.CreateCloudBlobClient();     CloudBlobDirectory directory =          client.GetBlobDirectoryReference(directoryName);      CloudBlobDirectory subDirectory =          directory.GetSubdirectory(subDirectoryName);       return subDirectory.ListBlobs(); } 

You can then call this as follows:

GetDirectoryList("content/blue", "images") 

Note the use of GetBlobDirectoryReference and GetSubDirectory methods and the CloudBlobDirectory type instead of CloudBlobContainer. These provide the traversal functionality you are likely looking for.

This should help you get started. Let me know if this doesn't answer your question:

[ Thanks to Neil Mackenzie for inspiration ]

like image 54
tobint Avatar answered Oct 07 '22 03:10

tobint


Are you referring to blob storage? If so, the hierarchy is simply StorageAccount/Container/BlobName. There are no nested containers.

Having said that, you can use slashes in your blob name to simulate nested containers in the URI. See this article on MSDN for naming details.

like image 36
David Makogon Avatar answered Oct 07 '22 02:10

David Makogon