我正在尝试获取有关Azure blob的一些信息(上次修改的UTC日期时间).此信息存储在CloudBlob.Properties.LastModifiedUtc属性中.
如果我使用方法GetBlobReference()或GetBlockBlobReference(),则不初始化blob的属性(LastModifiedUtc是DateTime.MinDate).如果我使用ListBlobs(),则属性被正确初始化(LastModifiedUtc具有正确的值).
使用GetBlobReference函数时我做错了吗?有没有办法如何为一个特定的blob获取CloudBlob实例?我知道我可以错过ListBlobs()并过滤我感兴趣的blob,或者使用CloudBlobClient类中的ListBlobsWithPrefix(),但是当我要求特定的Blob Reference时,我希望获得所有元数据.
显示我如何使用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 == …Run Code Online (Sandbox Code Playgroud)