未从 blob 上的 azure java sdk 收到元数据字段
Metadata fields not received from azure java sdk on a blob
在我们的 Azure 门户中,我创建了一个存储帐户,并在其中创建了一个 blob 容器,并在其中创建了一个 blob,它只是一个简单的文本文件。我还在此处看到的 blob 上设置了一些随机元数据字段。
在我的 java 代码中,当我通过 Azure SDK 访问 blob 时,我可以打印 blob 的内容,可以访问 Etag 等 blob 属性,还可以访问容器元数据。但是我无法打印上面看到的 blob 元数据字段。具体来说,从示例页面获取的这段代码不会打印任何内容,因为从 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();
}
如果我改为对 blob 进行 REST API 调用并请求元数据字段,我会将它们作为 HTTP headers 返回。但是,如果可能的话,我想通过 SDK 访问它们。
在blob.getMetadata()
之前,使用blob.downloadAttributes()
This method populates the blob's system properties and user-defined metadata. 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.
在我们的 Azure 门户中,我创建了一个存储帐户,并在其中创建了一个 blob 容器,并在其中创建了一个 blob,它只是一个简单的文本文件。我还在此处看到的 blob 上设置了一些随机元数据字段。
在我的 java 代码中,当我通过 Azure SDK 访问 blob 时,我可以打印 blob 的内容,可以访问 Etag 等 blob 属性,还可以访问容器元数据。但是我无法打印上面看到的 blob 元数据字段。具体来说,从示例页面获取的这段代码不会打印任何内容,因为从 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();
}
如果我改为对 blob 进行 REST API 调用并请求元数据字段,我会将它们作为 HTTP headers 返回。但是,如果可能的话,我想通过 SDK 访问它们。
在blob.getMetadata()
之前,使用blob.downloadAttributes()
This method populates the blob's system properties and user-defined metadata. 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.