在S3中没有“文件夹”和“文件”,有“桶”和“对象”
ListObjectsV2 - Amazon Simple Storage Service
返回的对象按列表中各个键名的升序排序
必须对存储桶具有 READ 访问权限
GET /?list-type=2&continuation-token=ContinuationToken&delimiter=Delimiter&encoding-type=EncodingType&fetch-owner=FetchOwner&max-keys=MaxKeys&prefix=Prefix&start-after=StartAfter HTTP/1.1 Host: Bucket.s3.amazonaws.com x-amz-request-payer: RequestPayer x-amz-expected-bucket-owner: ExpectedBucketOwner
响应格式
HTTP/1.1 200
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult>
<IsTruncated>boolean</IsTruncated>
<Contents>
<ETag>string</ETag>
<Key>string</Key>
<LastModified>timestamp</LastModified>
<Owner>
<DisplayName>string</DisplayName>
<ID>string</ID>
</Owner>
<Size>integer</Size>
<StorageClass>string</StorageClass>
</Contents>
...
<Name>string</Name>
<Prefix>string</Prefix>
<Delimiter>string</Delimiter>
<MaxKeys>integer</MaxKeys>
<CommonPrefixes>
<Prefix>string</Prefix>
</CommonPrefixes>
...
<EncodingType>string</EncodingType>
<KeyCount>integer</KeyCount>
<ContinuationToken>string</ContinuationToken>
<NextContinuationToken>string</NextContinuationToken>
<StartAfter>string</StartAfter>
</ListBucketResult>
CommonPrefixes:
在计算返回次数时,所有键(最多 1,000 个)汇总到一个公共前缀中算作一次返回。
CommonPrefixes仅当您指定分隔符时,响应才能包含
CommonPrefixes包含前缀和分隔符指定的字符串之间的所有键(如果有)键。
CommonPrefixes列出在由 指定的目录中充当子目录的键Prefix。
例如,如果前缀是notes/并且分隔符是斜杠 ( /) notes/summer/july,则公共前缀是 notes/summer/。在计算返回次数时,所有汇总到公共前缀中的键都算作一次返回
示例请求:列出所有keys
GET /?list-type=2 HTTP/1.1 Host: bucket.s3..amazonaws.com x-amz-date: 20160430T233541Z Authorization: authorization string Content-Type: text/plain
返回示例
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>bucket</Name>
<Prefix/>
<KeyCount>205</KeyCount>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>my-image.jpg</Key>
<LastModified>2009-10-12T17:50:30.000Z</LastModified>
<ETag>"fba9dede5f27731c9771645a39863328"</ETag>
<Size>434234</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
<Contents>
...
</Contents>
...
</ListBucketResult>
示例请求:使用 max-keys、prefix 和 start-after 参数列出键
GET /?list-type=2&max-keys=3&prefix=E&start-after=ExampleGuide.pdf HTTP/1.1 Host: quotes.s3..amazonaws.com x-amz-date: 20160430T232933Z Authorization: authorization string
返回示例
HTTP/1.1 200 OK
x-amz-id-2: gyB+3jRPnrkN98ZajxHXr3u7EFM67bNgSAxexeEHndCX/7GRnfTXxReKUQF28IfP
x-amz-request-id: 3B3C7C725673C630
Date: Sat, 30 Apr 2016 23:29:37 GMT
Content-Type: application/xml
Content-Length: length
Connection: close
Server: AmazonS3
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>quotes</Name>
<Prefix>E</Prefix>
<StartAfter>ExampleGuide.pdf</StartAfter>
<KeyCount>1</KeyCount>
<MaxKeys>3</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>ExampleObject.txt</Key>
<LastModified>2013-09-17T18:07:53.000Z</LastModified>
<ETag>"599bab3ed2c697f1d26842727561fd94"</ETag>
<Size>857</Size>
<StorageClass>REDUCED_REDUNDANCY</StorageClass>
</Contents>
</ListBucketResult>
示例请求:使用前缀和分隔符参数列出键
此示例说明了请求中前缀和分隔符参数的使用。对于此示例,我们假设您的存储桶中有以下键:
- sample.jpg
- photos/2006/January/sample.jpg
- photos/2006/February/sample2.jpg
- photos/2006/February/sample3.jpg
- photos/2006/February/sample4.jpg
以下 GET 请求使用 value 指定分隔符参数 /。
GET /?list-type=2&delimiter=/ HTTP/1.1 Host: example-bucket.s3..amazonaws.com x-amz-date: 20160430T235931Z Authorization: authorization string