gpt4 book ai didi

c# - 获取 azure 上虚拟文件夹中的 blob (BlobService.ListBlobs) (C#)

转载 作者:行者123 更新时间:2023-12-03 02:14:36 24 4
gpt4 key购买 nike

我正在使用 Azure 存储并使用 C# 进行编程。我在 Azure 上设置了一个容器,我可以将文件保存到容器内的虚拟文件夹中。

但是,我在访问容器内虚拟文件夹内的 blob 时遇到问题。例如说我有:

container1/virtualfolder/file1.png

我希望能够列出虚拟文件夹内的所有 blob(例如 file1.png 等)。我怎样才能只引用这些文件?我尝试过使用 BlobServices.ListBlob 但它返回容器中的所有内容。我尝试修改容器路径,但它返回“BadRequest”。我认为这是路径问题。

这是我的代码:

    public void getBlobOffServer()
{
string resourcePath = "container";
StartCoroutine(blobService.ListBlobs(getBlobListComplete, resourcePath));
}

private void getBlobListComplete(IRestResponse<BlobResults> response)
{
if (response.IsError)
{
Debug.Log("FAILED" + response.StatusCode + response.ErrorMessage);
}
else
{
for (int i = 0; i < response.Data.Blobs.Length; i++)
{
Debug.Log(response.Data.Blobs[i].Name);

}
isComplete = true;

}
}

最佳答案

一般情况下,您可以使用 GetDirectoryReferenceListBlobsSegmentedAsync 来获取虚拟文件夹中的所有 Blob。

string containerName = "container-1";
string directoryName = "virtualfolder";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
CloudBlobDirectory directory = container.GetDirectoryReference(directoryName);
var blobList = directory.ListBlobsSegmentedAsync(null).Result;
foreach (var blob in blobList.Results)
{
Console.WriteLine(blob.Uri.OriginalString.Substring(blob.Uri.OriginalString.LastIndexOf('/')+1));
}

结果:

enter image description here

关于c# - 获取 azure 上虚拟文件夹中的 blob (BlobService.ListBlobs) (C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71929517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com