Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ __Parameters__
|``bucket_name`` | _string_ | Name of the bucket.|
|``prefix``| _string_ |The prefix of the objects that should be listed. Optional, default is None.|
|``recursive`` | _bool_ |``True`` indicates recursive style listing and ``False`` indicates directory style listing delimited by '/'. Optional, default is False.|
|``start_after``| _string_ | Starting listing after the specified path. Optional, default is None.|

__Return Value__

Expand All @@ -270,7 +271,7 @@ __Example__
```py
# List all object paths in bucket that begin with my-prefixname.
objects = minioClient.list_objects_v2('mybucket', prefix='my-prefixname',
recursive=True)
recursive=True, start_after='start-after-this-prefix')
for obj in objects:
print(obj.bucket_name, obj.object_name.encode('utf-8'), obj.last_modified,
obj.etag, obj.size, obj.content_type)
Expand Down
13 changes: 12 additions & 1 deletion minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def list_objects(self, bucket_name, prefix='', recursive=False):
for obj in objects:
yield obj

def list_objects_v2(self, bucket_name, prefix='', recursive=False):
def list_objects_v2(self, bucket_name, prefix='', recursive=False, start_after=''):
"""
List objects in the given bucket using the List objects V2 API.

Expand Down Expand Up @@ -939,6 +939,13 @@ def list_objects_v2(self, bucket_name, prefix='', recursive=False):
# hello/world/1
# hello/world/2


objects = minio.list_objects_v2('foo', recursive=True,
start_after='hello/world/1')
for current_object in objects:
print(current_object)
# hello/world/2

:param bucket_name: Bucket to list objects from
:param prefix: String specifying objects returned must begin with
:param recursive: If yes, returns all objects for a specified prefix
Expand All @@ -950,9 +957,13 @@ def list_objects_v2(self, bucket_name, prefix='', recursive=False):
if prefix is None:
prefix = ''

if start_after is None:
start_after = ''

# Initialize query parameters.
query = {
'list-type': '2',
'start-after': start_after,
'prefix': prefix
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/list_objects_v2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_empty_list_objects_works(self, mock_connection):
mock_server = MockConnection()
mock_connection.return_value = mock_server
mock_server.mock_add_request(MockResponse('GET',
'https://localhost:9000/bucket/?list-type=2&prefix=',
'https://localhost:9000/bucket/?list-type=2&prefix=&start-after=',
{'User-Agent': _DEFAULT_USER_AGENT}, 200, content=mock_data))
client = Minio('localhost:9000')
object_iter = client.list_objects_v2('bucket', recursive=True)
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_list_objects_works(self, mock_connection):
mock_server.mock_add_request(
MockResponse(
'GET',
'https://localhost:9000/bucket/?delimiter=%2F&list-type=2&prefix=',
'https://localhost:9000/bucket/?delimiter=%2F&list-type=2&prefix=&start-after=',
{'User-Agent': _DEFAULT_USER_AGENT}, 200,
content=mock_data
)
Expand Down