gpt4 book ai didi

使用 GetBlobReference() 时,Azure 存储 CloudBlob.Properties 未初始化

转载 作者:行者123 更新时间:2023-12-03 15:13:47 25 4
gpt4 key购买 nike

我正在尝试获取有关 Azure blob(上次修改的 UTC 日期时间)的一些信息。此信息存储在 CloudBlob.Properties.LastModifiedUtc 属性中。

如果我使用方法 GetBlobReference() 或 GetBlockBlobReference(),则 blob 的属性不会初始化(LastModifiedUtc 为 DateTime.MinDate)。如果我使用 ListBlobs(),属性将正确初始化(LastModifiedUtc 具有正确的值)。

使用 GetBlobReference 函数时我做错了什么吗?有没有一种方法可以为一个特定的 blob 获取 CloudBlob 实例?我知道我可以错过 ListBlobs() 并仅过滤我感兴趣的 Blob,或者使用 CloudBlobClient 类中的 ListBlobsWithPrefix(),但我希望在请求特定 Blob 引用时获取所有元数据。

显示我如何使用 Azure blob 的代码:

    string storageAccountName = "test";
string storageAccountKey = @"testkey";
string blobUrl = "https://test.blob.core.windows.net";
string containerName = "testcontainer";
string blobName = "testbontainer";

var credentials = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey);
var cloudBlobClient = new CloudBlobClient(blobUrl, credentials);
var containerReference = cloudBlobClient.GetContainerReference(string.Format("{0}/{1}", blobUrl, containerName));

// OK - Result is of type CloudBlockBlob, cloudBlob_ListBlobs.Properties.LastModifiedUtc > DateTime.MinValue
var cloudBlob_ListBlobs = containerReference.ListBlobs().Where(i => i is CloudBlob && ((CloudBlob)i).Name == blobName).FirstOrDefault() as CloudBlob;

// WRONG - Result is of type CloudBlob, cloudBlob_GetBlobReference.Properties.LastModifiedUtc == DateTime.MinValue
var cloudBlob_GetBlobReference = containerReference.GetBlobReference(string.Format("{0}/{1}/{2}", blobUrl, containerName, blobName));

// WRONG - Result is of type CloudBlockBlob, cloudBlob_GetBlockBlobReference.Properties.LastModifiedUtc == DateTime.MinValue
var cloudBlob_GetBlockBlobReference = containerReference.GetBlockBlobReference(string.Format("{0}/{1}/{2}", blobUrl, containerName, blobName));

最佳答案

我相信您必须进行单独的调用才能获取属性/元数据。获得 blob 引用后,发出以下行来检索属性。

cloudBlob_GetBlobReference.FetchAttributes();

关于使用 GetBlobReference() 时,Azure 存储 CloudBlob.Properties 未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9994777/

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