如何创建Azure存储位置的子容器 [英] How to create a sub container in azure storage location

查看:230
本文介绍了如何创建Azure存储位置的子容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在蔚蓝的存储位置创建一个子容器。

How to create a sub container in the azure storage location.

请让我们知道

推荐答案

Windows Azure中不提供heirarchical容器的概念,但它确实提供了一个机制,按照惯例和API来遍历层次结构。所有容器都存储在同一水平。您可以通过使用命名约定为您的blob名获得这类似于功能。

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

注意,这些斑点是对你的内容容器一个平坦的列表。也就是说,使用/作为分隔符的常规,为您提供的功能在heirarchical的方式遍历这些。

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 = 
        cloudBlobClient.GetBlobDirectoryReference(directoryName); 
    CloudBlobDirectory subDirectory = 
        directory.GetSubdirectory(subDirectoryName); 

    return subDirectory.ListBlobs();
}

您可以调用这个如下:

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

注意使用 GetBlobDirectoryReference GetSubDirectory 的方法和在 CloudBlobDirectory 类型,而不是 CloudBlobContainer 。这些提供了你很可能寻找穿越功能。

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:

[感谢尼尔·麦肯齐]

这篇关于如何创建Azure存储位置的子容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆