gpt4 book ai didi

c# - 访问 Azure 中的 Blob 属性

转载 作者:行者123 更新时间:2023-11-30 21:41:37 24 4
gpt4 key购买 nike

我需要获取 blob 属性,其中有最后修改日期。我需要日期来进行比较。阅读了很多文章,并认为这是因为我没有使用 CloudBlockBlob,但我无法从中提取属性。

到目前为止,我的代码返回了 blob 的名称:

public static void ListBlobsAnonymously()
{
//Get the blob from the URL - URL is in the app.config file so it can be changed easily should it need it.
CloudBlobContainer container = new CloudBlobContainer(new Uri(ConfigurationManager.AppSettings["VOURL"]));

//For each of the blobs, write the file name out. This will be needed for a comparison.
foreach (IListBlobItem blobItem in container.ListBlobs())
{
string name = blobItem.Uri.Segments.Last();
Console.WriteLine(name);
}

Console.ReadKey();
}

这是 blob 的结构:

<EnumerationResults ServiceEndpoint="https://test.blob.core.windows.net/" ContainerName="downloads">
<Blobs>
<Blob>
<Name>
This_is_a_test
</Name>
<Properties>
<Last-Modified>Tue, 01 Oct 2010 14:33:48 GMT</Last-Modified>
<Content-Length>452</Content-Length>
<Content-Type>application/zip</Content-Type>
<BlobType>BlockBlob</BlobType>
</Properties>
</Blob>
</Blobs>
</EnumerationResults>

这是我需要获取但无法获取的属性中的最后一个修改。

最佳答案

尝试以下代码:(注意:不支持/在 NET Core 上工作)

        CloudBlobContainer container = new CloudBlobContainer(new Uri(ConfigurationManager.AppSettings["VOURL"]));

//For each of the blobs, write the file name out. This will be needed for a comparison.
foreach (IListBlobItem blobItem in container.ListBlobs())
{
var blob = (CloudBlob)blobItem;
if (blob != null)
{
string name = blobItem.Uri.Segments.Last();
Console.WriteLine(name);
Console.WriteLine(blob.Properties.LastModified);
}
}

Console.ReadKey();

基本上,您需要将 IListBlobItem 转换为 CloudBlob,然后您就可以访问 Blob 的属性。

关于c# - 访问 Azure 中的 Blob 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43119786/

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