gpt4 book ai didi

c# - 检索 blob 文件名

转载 作者:行者123 更新时间:2023-11-30 19:10:52 24 4
gpt4 key购买 nike

因此,我正在尝试检索 Blob 存储中的文件的详细信息。这个想法是客户要求将与他们具体相关的文档放置在他们的门户上。

这是一次迁移,当前文件以以下格式列在网格中:

文件名、文件大小、文件类型、下载链接。

我遇到的问题是检索 blob 属性。

这是我目前拥有的代码片段。

public void BindGridDocuments()
{
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString);
var blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference("documents");
var documentCollection = container.ListBlobs();
foreach (var document in documentCollection)
{
string filename = document.Uri.ToString();

}
}

最佳答案

试试这个代码。代码假定 Blob 容器中的所有 Blob 均为 block Blob 类型。

存储客户端库2.0:

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("images");
var blobs = blobContainer.ListBlobs(null, true, BlobListingDetails.All).Cast<CloudBlockBlob>();
foreach (var blockBlob in blobs)
{
Console.WriteLine("Name: " + blockBlob.Name);
Console.WriteLine("Size: " + blockBlob.Properties.Length);
Console.WriteLine("Content type: " + blockBlob.Properties.ContentType);
Console.WriteLine("Download location: " + blockBlob.Uri);
Console.WriteLine("=======================================");
}

存储客户端库 1.7:

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("images");
var blobs = blobContainer.ListBlobs(new BlobRequestOptions()
{
BlobListingDetails = BlobListingDetails.All,
UseFlatBlobListing = true,
}).Cast<CloudBlockBlob>();
foreach (var blockBlob in blobs)
{
Console.WriteLine("Name: " + blockBlob.Name);
Console.WriteLine("Size: " + blockBlob.Properties.Length);
Console.WriteLine("Content type: " + blockBlob.Properties.ContentType);
Console.WriteLine("Download location: " + blockBlob.Uri);
Console.WriteLine("=======================================");
}

关于c# - 检索 blob 文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14895548/

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