【发布时间】:2015-03-17 05:59:22
【问题描述】:
我正在尝试获取有关 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));
【问题讨论】:
标签: azure blob azure-blob-storage