简体   繁体   English

从Azure存储Blob访问元数据

[英]Accessing metadata from azure storage blob

I can't seem to find a method to access individual blob metadata for blobs in Azure Storage. 我似乎找不到在Azure存储中访问单个Blob元数据的方法。

FetchAttributes only works on the whole container. FetchAttributes仅适用于整个容器。 My method returns a list of blobs which match the parameters I set. 我的方法返回与我设置的参数匹配的Blob列表。 I then need to iterate through that list and retrieve some metadata from each of those blobs but I am not finding any methods to do so. 然后,我需要遍历该列表并从每个blob中检索一些元数据,但我没有找到任何方法可以这样做。

It seems like a lot of overhead, but should I be Fetching those attributes when I create the container object, and then filtering for the blob list? 似乎有很多开销,但是在创建容器对象时是否应该获取这些属性,然后过滤blob列表?

So, I figured I'd try that, 所以,我想我会尝试的,

 public static IEnumerable<GalleryPhoto> GetGalleryPhotos(string folderPath)
 {

        var container = CreateAzureContainer(containerName, false);
        container.FetchAttributes();
        var blobDirectory = container.GetDirectoryReference(folderPath);
        var photoGalleries = new List<GalleryPhoto>();
        var blobs = blobDirectory.ListBlobs().ToList();

       ...rest of code
  }

The blob objects in blobs, show 0 for the metadata count. Blob中的Blob对象的元数据计数显示为0。 Each of the items HAVE metadata, verified by looking at the properties in Azure Storage Explorer for each blob. 每个项目都具有元数据,通过查看Azure存储资源管理器中每个Blob的属性进行验证。

Any help appreciated. 任何帮助表示赞赏。

It is entirely possible to fetch the metadata in result when listing blobs. 列出斑点时,完全有可能获取结果中的元数据。 What you would need to do is specify BlobListingDetails parameter in ListBlobs method call and specify BlobListingDetails.Metadata there. 您需要做的是在ListBlobs方法调用中指定BlobListingDetails参数,并在ListBlobs指定BlobListingDetails.Metadata What this will do is include metadata for each blob in the response. 这将在响应中包括每个Blob的元数据。 So your code would be: 因此您的代码将是:

public static IEnumerable<GalleryPhoto> GetGalleryPhotos(string folderPath)
 {

        var container = CreateAzureContainer(containerName, false);
        container.FetchAttributes();
        var blobDirectory = container.GetDirectoryReference(folderPath);
        var photoGalleries = new List<GalleryPhoto>();
        var blobs = blobDirectory.ListBlobs(false, BlobListingDetails.Metadata).ToList();

       ...rest of code
  }

Do give this a try. 尝试一下。 It should work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM