简体   繁体   English

未从 blob 上的 azure java sdk 收到元数据字段

[英]Metadata fields not received from azure java sdk on a blob

In our Azure portal I have created a storage account and inside created a blob container and inside that a blob which is just a simple text file.在我们的 Azure 门户中,我创建了一个存储帐户,并在其中创建了一个 blob 容器,并在其中创建了一个 blob,它只是一个简单的文本文件。 I have also set the some random metadata fields on the blob seen here.我还在此处看到的 blob 上设置了一些随机元数据字段。 在此处输入图片说明

In my java code when I access the blob via the Azure SDK I can print the content of the blob, I can acccess the blob properties like the Etag and I can access the container metadata.在我的 java 代码中,当我通过 Azure SDK 访问 blob 时,我可以打印 blob 的内容,我可以访问 blob 属性,如 Etag,我可以访问容器元数据。 But I cannot print the blob metadata fields seen above.但是我无法打印上面看到的 blob 元数据字段。 Specifically this code taken from the samples page doesn't print anything since the received HashMap from blob.getMetadata() method is empty.具体来说,从示例页面中获取的这段代码不会打印任何内容,因为从blob.getMetadata()方法接收到的 HashMap 是空的。

System.out.println("Get blob metadata:"); 
             HashMap<String, String> metadata = blob.getMetadata(); 
             Iterator it = metadata.entrySet().iterator(); 
             while (it.hasNext()) { 
                Map.Entry pair = (Map.Entry) it.next(); 
                 System.out.printf(" %s = %s%n", pair.getKey(), pair.getValue()); 
                 it.remove(); 
             } 

If I instead make a REST API call to the blob and ask for the metadata fields I do get them back as HTTP headers.如果我改为对 blob 进行 REST API 调用并请求元数据字段,我会将它们作为 HTTP 标头返回。 However I would like to access them via the SDK if possible.但是,如果可能,我想通过 SDK 访问它们。

Before blob.getMetadata() , use blob.downloadAttributes()blob.getMetadata()之前,使用blob.downloadAttributes()

This method populates the blob's system properties and user-defined metadata.此方法填充 blob 的系统属性和用户定义的元数据。 Before reading or modifying a blob's properties or metadata, call this method or its overload to retrieve the latest values for the blob's properties and metadata from the Microsoft Azure storage service.在读取或修改 Blob 的属性或元数据之前,调用此方法或其重载以从 Microsoft Azure 存储服务检索 Blob 的属性和元数据的最新值。

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

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