Amazon S3:在单个请求中列出带有元数据的对象 [英] Amazon S3 : Listing Object with Metadata in single request

查看:70
本文介绍了Amazon S3:在单个请求中列出带有元数据的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Amazon服务的新手,我正在使用Amazon s3进行文件存储.我使用以下代码列出了对象.

I am new to Amazon services, I am using amazon s3 for file storing. I used following code to listing object.

ListObjectsRequest lor = new ListObjectsRequest().withBucketName("BUCKETNAME");
ObjectListing objectListing = amazonS3Client.listObjects(lor);
for (S3ObjectSummary summary: objectListing.getObjectSummaries()) {
    fileKeys.add(summary.getKey());
}

我想在上述单个请求中获取所有对象的元数据.

I want to get the all objects meta data in single above request.

这是可能吗??

推荐答案

没有API可以向您提供对象列表及其元数据.

There is no API that will give you list of objects along with their metadata.

ListObjectsRequest :此请求返回有关指定存储桶中对象的摘要信息列表.根据请求参数,将返回其他信息,例如,如果指定了分隔符,则将使用公共前缀.列表结果始终按字典顺序(字母顺序)返回.

ListObjectsRequest : This request return a list of summary information about the objects in the specified bucket. Depending on the request parameters, additional information is returned, such as common prefixes if a delimiter was specified. List results are always returned in lexicographic (alphabetical) order.

您可以从lisObject返回的objectSummary中获取四个默认元数据:Last Modified, Storage Type, Etag and Size.

You can get four default metadata from objectSummary that returned from lisObject : Last Modified, Storage Type, Etag and Size.

要获取对象的元数据,您需要执行

To get metadata of objects, you need to perform HEAD object request on object or you call following method on your object :

GetObjectMetadataRequest(String bucketName, String key)

看看这个:

 ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
                    .withBucketName(bucketName);
            ObjectListing objectListing;
            do {
                objectListing = s3client.listObjects(listObjectsRequest);
                for (S3ObjectSummary objectSummary
                        : objectListing.getObjectSummaries()) {
                    /** Default Metadata **/
                    Date dtLastModified = objectSummary.getLastModified();
                    String sEtag = objectSummary.getETag();
                    long lSize = objectSummary.getSize();
                    String sStorageClass = objectSummary.getStorageClass();
                    /** To get user defined metadata **/
                    ObjectMetadata objectMetadata = s3client.getObjectMetadata(bucketName, objectSummary.getKey());
                    Map userMetadataMap = objectMetadata.getUserMetadata();
                    Map rowMetadataMap = objectMetadata.getRawMetadata();
                }
                listObjectsRequest.setMarker(objectListing.getNextMarker());
            } while (objectListing.isTruncated());

有关GetObjectMetadataRequest的更多详细信息,请查看以下链接.

For more details on GetObjectMetadataRequest, look this link.

这篇关于Amazon S3:在单个请求中列出带有元数据的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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