如何在azure存储位置创建子容器

发布于 2024-09-08 04:07:42 字数 25 浏览 3 评论 0原文

如何在azure存储位置创建子容器?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

撧情箌佬 2024-09-15 04:07:42

Windows Azure 不提供分层容器的概念,但它确实提供了一种通过约定和 API 遍历分层结构的机制。所有容器均存放在同一层。您可以通过使用 Blob 名称的命名约定来获得类似的功能。

例如,您可以创建一个名为“content”的容器,并在该容器中创建具有以下名称的 blob:

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

注意这些 blob 是针对“content”容器的平面列表。也就是说,使用“/”作为常规分隔符,为您提供了以分层方式遍历这些分隔符的功能。

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();
}

然后,您可以按如下方式调用它:

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

注意使用GetBlobDirectoryReferenceGetSubDirectory方法以及CloudBlobDirectory类型而不是CloudBlobContainer。这些提供了您可能正在寻找的遍历功能。

这应该可以帮助您入门。如果这不能回答您的问题,请告诉我:

[ 感谢 Neil Mackenzie 寻找灵感]

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 ]

扶醉桌前 2024-09-15 04:07:42

您指的是 blob 存储吗?如果是这样,层次结构就是 StorageAccount/Container/BlobName。没有嵌套容器。

尽管如此,您可以在 blob 名称中使用斜杠来模拟 URI 中的嵌套容器。有关命名详细信息,请参阅MSDN 上的这篇文章

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.

忘羡 2024-09-15 04:07:42

我同意托宾特的回答,我想在这种情况下添加一些内容,因为我也
我需要以相同的方式将我的游戏 html 上传到 Azure 存储并创建以下目录:

  • Games\Beautyshop\index.html
  • Games\Beautyshop\assets\apple.png
  • Games\Beautyshop\assets\aromas.png
  • Games\Beautyshop\customfont.css
  • Games \Beautyshop\jquery.js

因此,在您的建议之后,我尝试使用 Azure Storage Explorer 工具上传我的内容,您可以使用以下网址下载工具和源代码: Azure 存储资源管理器

首先,我尝试通过工具上传,但它不允许分层目录上传,因为你不需要: 如何在 blob 容器中创建子目录

最后,我调试 Azure 存储Explorer 源代码和我编辑了 StorageAccountViewModel.cs 文件中的 Background_UploadBlobs 方法和 UploadFileList 字段。您可以编辑您想要的内容。我可能犯了拼写错误:/我很抱歉,但这只是我的建议。

I aggree with tobint answer and I want to add something this situation because I also
I need the same way upload my games html to Azure Storage with create this directories :

  • Games\Beautyshop\index.html
  • Games\Beautyshop\assets\apple.png
  • Games\Beautyshop\assets\aromas.png
  • Games\Beautyshop\customfont.css
  • Games\Beautyshop\jquery.js

So After your recommends I tried to upload my content with tool which is Azure Storage Explorer and you can download tool and source code with this url : Azure Storage Explorer

First of all I tried to upload via tool but It doesn't allow to hierarchical directory upload because you don't need : How to create sub directory in a blob container

Finally, I debug Azure Storage Explorer source code and I edited Background_UploadBlobs method and UploadFileList field in StorageAccountViewModel.cs file. You can edit it what you wants.I may have made spelling errors :/ I am so sorry but That's only my recommend.

乖乖哒 2024-09-15 04:07:42

如果您要从 Azure 门户上传文件:
要在容器中创建子文件夹,在上传文件时,您可以转到高级选项并选择上传到文件夹,这将在容器中创建一个新文件夹并将文件上传到其中。

If you are tying to upload files from Azure portal:
To create a sub folder in container, while uploading a file you can go to Advanced options and select upload to a folder, which will create a new folder in the container and upload the file into that.

迎风吟唱 2024-09-15 04:07:42

Kotlin 代码

    val blobClient = blobContainerClient.getBlobClient("$subDirNameTimeStamp/$fileName$extension");

将创建以 TimeStamp 为名称的目录,其中包含您的 Blob 文件。请注意上面代码中斜杠 (/) 的使用,它将通过创建名为前面的斜杠字符串的文件夹来嵌套 blob 文件。

它在门户上看起来像这样
输入图片此处描述

Kotlin Code

    val blobClient = blobContainerClient.getBlobClient("$subDirNameTimeStamp/$fileName$extension");

this will create directory having TimeStamp as name and inside that there will be your Blob File. Notice the use of slash (/) in above code which will nest your blob file by creating folder named as previous string of slash.

It will look like this on portal
enter image description here

伴随着你 2024-09-15 04:07:42

示例代码

string myfolder = "<folderName>";
string myfilename = "<fileName>";
string fileName = String.Format("{0}/{1}.csv", myfolder, myfilename);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

Sample code

string myfolder = "<folderName>";
string myfilename = "<fileName>";
string fileName = String.Format("{0}/{1}.csv", myfolder, myfilename);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文