使用GetBlobReference时(Azure存储CloudBlob.Properties不会被初始化) [英] Azure Storage CloudBlob.Properties are not initialized when using GetBlobReference()

查看:537
本文介绍了使用GetBlobReference时(Azure存储CloudBlob.Properties不会被初始化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得关于Azure的BLOB(最后修改UTC日期时间)的一些信息。这个信息被存储CloudBlob.Properties.LastModifiedUtc属性

如果我使用的方法GetBlobReference()或GetBlockBlobReference(),BLOB的属性不会被初始化(LastModifiedUtc是DateTime.MinDate)。如果我使用ListBlobs()属性的正确初始化(LastModifiedUtc有正确的值)。

使用GetBlobReference功能时,难道我做错了什么?有一些路怎么走CloudBlob实例只为一个特定的斑点?我知道我可以missue ListBlobs()和过滤只是一滴我感兴趣的,或者使用从类CloudBlobClient ListBlobsWith preFIX(),但我希望让所有的元数据时,我问具体的斑点参考。

code展示我如何与Azure的斑点工作:

 字符串storageAccountName =测试;
    字符串storageAccountKey = @密押
    字符串blobUrl =htt​​ps://test.blob.core.windows.net;
    字符串容器名称=testcontainer;
    字符串blobName =testbontainer;    VAR证书=新StorageCredentialsAccountAndKey(storageAccountName,storageAccountKey);
    VAR cloudBlobClient =新CloudBlobClient(blobUrl,证书);
    VAR containerReference = cloudBlobClient.GetContainerReference(的String.Format({0} / {1},blobUrl,容器名称));    // OK - 结果类型CloudBlockBlob的,cloudBlob_ListBlobs.Properties.LastModifiedUtc> DateTime.MinValue
    变种cloudBlob_ListBlobs = containerReference.ListBlobs()式(I = I标记是CloudBlob&放大器;及((CloudBlob)ⅰ).Name点== blobName)。.FirstOrDefault()作为CloudBlob;    // WRONG - 结果类型CloudBlob的,cloudBlob_GetBlobReference.Properties.LastModifiedUtc == DateTime.MinValue
    VAR cloudBlob_GetBlobReference = containerReference.GetBlobReference(的String.Format({0} / {1} / {2},blobUrl,容器名称,blobName));    // WRONG - 结果类型CloudBlockBlob的,cloudBlob_GetBlockBlobReference.Properties.LastModifiedUtc == DateTime.MinValue
    VAR cloudBlob_GetBlockBlobReference = containerReference.GetBlockBlobReference(的String.Format({0} / {1} / {2},blobUrl,容器名称,blobName));


解决方案

我相信你必须做出一个单独的调用来获取属性/元。之后,你有团块参鉴,发出以下行来检索的属性。

cloudBlob_GetBlobReference.FetchAttributes();

I'm trying to get some information about Azure blob (last modified UTC date time). This information is stored CloudBlob.Properties.LastModifiedUtc property.

If I use method GetBlobReference() or GetBlockBlobReference(), the Properties of the blob are not initialized (LastModifiedUtc is DateTime.MinDate). If I use ListBlobs() the Properties are initialized correctly (LastModifiedUtc has correct value).

Am I doing something wrong when using GetBlobReference function? Is there some way how to get CloudBlob instance just for one specific blob? I know I can missue ListBlobs() and filter just the blob I'm interested in, or use ListBlobsWithPrefix() from class CloudBlobClient, but I would expect to get all the metadata when I ask for specific Blob Reference.

Code showing how I'm working with Azure blobs:

    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));

解决方案

I believe you have to make a seperate call to fetch the attributes/metadata. After you have the blob referrence, issue the following line to retrieve the attributes.

cloudBlob_GetBlobReference.FetchAttributes();

这篇关于使用GetBlobReference时(Azure存储CloudBlob.Properties不会被初始化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆