如何在 azure 存储位置创建子容器 [英] How to create a sub container in azure storage location
问题描述
如何在 azure 存储位置创建子容器?
Windows Azure 不提供分层容器的概念,但它确实提供了一种通过约定和 API 遍历分层结构的机制.所有容器都存储在同一层.您可以通过对 blob 名称使用命名约定来获得类似的功能.
例如,您可以创建一个名为content"的容器,并在该容器中创建具有以下名称的 blob:
content/blue/images/logo.jpg内容/蓝色/图像/icon-start.jpg内容/蓝色/图像/icon-stop.jpg内容/红色/图像/logo.jpg内容/红色/图像/icon-start.jpg内容/红色/图像/icon-stop.jpg
注意,这些 blob 是针对您的内容"容器的平面列表.也就是说,使用/"作为传统的分隔符,为您提供了以分层方式遍历这些的功能.
protected IEnumerableGetDirectoryList(string directoryName, string subDirectoryName){CloudStorageAccount 帐户 =CloudStorageAccount.FromConfigurationSetting("DataConnectionString");CloudBlobClient 客户端 =account.CreateCloudBlobClient();CloudBlobDirectory 目录 =client.GetBlobDirectoryReference(directoryName);CloudBlobDirectory 子目录 =directory.GetSubdirectory(subDirectoryName);返回 subDirectory.ListBlobs();}
然后你可以这样调用它:
GetDirectoryList("content/blue", "images")
注意使用 GetBlobDirectoryReference 和 GetSubDirectory 方法和 CloudBlobDirectory 类型而不是 CloudBlobContainer强>.这些提供了您可能正在寻找的遍历功能.
这应该可以帮助您入门.如果这不能回答您的问题,请告诉我:
[ 感谢 Neil Mackenzie 的灵感]>
How can I create a sub container in the azure storage location?
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 ]
这篇关于如何在 azure 存储位置创建子容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!