1.12.7 List Objects
优质
小牛编辑
125浏览
2023-12-01
描述
该操作用于列出Bucket下的Objects。
单次操作最多可列出1000个Objects。如果需要列出Bucket下的所有Objects,则需要循环执行该操作。
可以通过prefix参数只将Bucket下包含特定前缀的objects列出。 Delimiter参数可以用于将相同prefix的objects聚合在一起。例如,Bucket下有2016/05.log和2016/06.log,如果指定delimiter为'/',则只返回2016这个公共前缀。
Note
- 如果需要列出用户的所有Buckets,请参考List Buckets。
Restful 接口
参考
Note
如果prefix和delimiter都非空,则prefix必须以delimiter结尾。
SDK 接口
- Java SDK: listObjects, listNextBatchOfObjects
- go SDK: List_Object, List_Next_Batch_Of_Objects
- C++ SDK: listObjects, listNextBatchOfObjects
- Php SDK: listObjects, listNextBatchOfObjects
- python SDK: list_objects, list_next_batch_of_objects
参数使用示例
假设fds-demo下有如下Objects
- bar/bang/bang
- bar/baz
- bee
- foo/bang
- foo/bash
请求示例(prefix和delimiter都为空)
PUT /test-bucket-name?prefix=&delimiter= HTTP/1.1 HOST: files.fds.api.xiaomi.com Content-Length: 0 Date: Wed, 01 Mar 2006 12:00:00 GMT Authorization: authorization string
响应示例
HTTP/1.1 200 OK Date: Wed, 01 Mar 2006 12:00:00 GMT Content-Length: 535 Connection: close {"commonPrefixes":[],"delimiter":"","marker":"","maxKeys":1000,"name":"test-bucket-name","objects":[{"name":"bar/bang/bang","owner":{"id":"109934"},"size":14,"uploadTime":1453881434148},{"name":"bar/baz","owner":{"id":"109934"},"size":14,"uploadTime":1453881434167},{"name":"bee","owner":{"id":"109934"},"size":14,"uploadTime":1453881434181},{"name":"foo/bang","owner":{"id":"109934"},"size":14,"uploadTime":1453881434129},{"name":"foo/bash","owner":{"id":"109934"},"size":14,"uploadTime":1453881433642}],"prefix":"","truncated":false}
请求示例(prefix非空,delimiter为空)
PUT /test-bucket-name?prefix=foo&delimiter= HTTP/1.1 HOST: files.fds.api.xiaomi.com Content-Length: 0 Date: Wed, 01 Mar 2006 12:00:00 GMT Authorization: authorization string
响应示例
HTTP/1.1 200 OK Date: Wed, 01 Mar 2006 12:00:00 GMT Content-Length: 296 Connection: close {"commonPrefixes":[],"delimiter":"","marker":"","maxKeys":1000,"name":"test-bucket-name","objects":[{"name":"foo/bang","owner":{"id":"109934"},"size":14,"uploadTime":1453881434129},{"name":"foo/bash","owner":{"id":"109934"},"size":14,"uploadTime":1453881433642}],"prefix":"foo","truncated":false}
请求示例(prefix为空,delimiter非空)
PUT /test-bucket-name?prefix=&delimiter=/ HTTP/1.1 HOST: files.fds.api.xiaomi.com Content-Length: 0 Date: Wed, 01 Mar 2006 12:00:00 GMT Authorization: authorization string
响应示例
HTTP/1.1 200 OK Date: Wed, 01 Mar 2006 12:00:00 GMT Content-Length: 221 Connection: close {"commonPrefixes":["bar/","foo/"],"delimiter":"/","marker":"","maxKeys":1000,"name":"test-bucket-name","objects":[{"name":"bee","owner":{"id":"109934"},"size":14,"uploadTime":1453881434181}],"prefix":"","truncated":false}
请求示例(prefix和delimiter都非空)
PUT /test-bucket-name?prefix=bar/&delimiter=/ HTTP/1.1 HOST: files.fds.api.xiaomi.com Content-Length: 0 Date: Wed, 01 Mar 2006 12:00:00 GMT Authorization: authorization string
响应示例
HTTP/1.1 200 OK Date: Wed, 01 Mar 2006 12:00:00 GMT Content-Length: 227 Connection: close {"commonPrefixes":["bar/bang/"],"delimiter":"/","marker":"","maxKeys":1000,"name":"test-bucket-name","objects":[{"name":"bar/baz","owner":{"id":"109934"},"size":14,"uploadTime":1453881434167}],"prefix":"bar/","truncated":false}