List Objects in a Bucket
List all Objects by Pagination
This SDK method will allow you to get all the objects present in a particular bucket by pagination. The Bucket reference used in the below code snippet is the component instance.
For each call, a limited number of objects will be returned, and the next call will be initiated only if a continuation token is returned.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
max_keys | String | A Mandatory parameter. Will contain the maximum limit of objects that can be listed by pagination. |
continuation_token | String | An Mandatory parameter. Will contain the token to get the next set of objects. |
prefix | String | An Optional parameter. To list objects that match the prefix value. |
In the following SDK method, a maximum value of pagination is set using max_keys. Using prefix, you can list objects that only match the prefix:.
The response we get will contain the following properties of the bucket, which will be stored in moreOptions:
- key count: Will contain the value of the number of objects that are being returned
- max_key: The maximum limit of objects that can be returned
- Truncated: Will contain the status to notify if a bucket is truncated or not.
- contents: List of object details
- next_token: If the response was truncated, the value of this key must be passed as next_token to the same method for retrieving the next set of objects.
With each iteration, we will list the max_keys number of objects and check if next_token has been created. Using next_token we will continue the iteration till all the objects have been listed.
copydef list_my_paged_objects(max_keys=None, prefix=None, next_token=None): data = bucket.list_paged_objects( max_keys, prefix, next_token ) # return the max key number of objects print(data) if data["is_truncated"]: # If it is return true means number of objects is more than the max_keys. Return 'false' there is no keys found for next iteration. list_my_paged_objects(max_keys, prefix, data["next_continuation_token"]) # get next set of objects list_my_paged_objects(5, "sam")
Example Response
copy{ "prefix": "sam", "key_count": "5", "max_keys": "5", "truncated": "True", "next_continuation_token": "47VrqTzR9ukMF9gr8YcziVVzdRP5GCjq1NfM5fMBpMfvw5qcXFRSueuqCTRUCzNd9dHfquXHi2afDanLH6MbyJo6", "contents": [ { "key_type": "file", "key": "sam1s2ww.mp4", "size": "427160684", "content_type": "video/mp4", "etag": "78c2b173b56cd944e9c79abd601f6073", "last_modified": "May 21, 2024 01:00 PM" }, { "key_type": "file", "key": "samdm.txt", "size": "23", "content_type": "text/plain; charset=utf-8", "etag": "c0122754f465e42eb97b5af174663c29", "last_modified": "May 14, 2024 01:30 PM" }, { "key_type": "file", "key": "samplvbse1.json", "size": "8", "content_type": "application/json", "etag": "499e7dbaee453352a9c17407a676dbda", "last_modified": "May 13, 2024 10:05 AM" }, { "key_type": "file", "key": "samplse1.json", "size": "8", "content_type": "application/json", "etag": "499e7dbaee453352a9c17407a676dbda", "last_modified": "May 13, 2024 09:20 AM" }, { "key_type": "file", "key": "sampjkhdldbed.mp4", "size": "0", "content_type": "video/mp4", "etag": "d41d8cd98f00b204e9800998ecf8427e", "last_modified": "May 12, 2024 10:54 PM" } ] }
List Objects Through Iteration
Using this SDK method, you can get all the objects present in a bucket in a single API call, using iteration technique. The Bucket reference used in the below code snippet is the component instance.
copyobjects = bucket.list_iterated_objects(max_keys=2, prefix='sam') for key in objects: print(key)
Example Response
copy{ "key_type": "file", "key": "ssdgs.mp4", "size": "3145728", "content_type": "video/mp4", "etag": "9685b8d5b8b719274bac854b897d95ec", "last_modified": "May 21, 2024 03:49 PM" } { "key_type": "file", "key": "Sasss.mp4", "size": "2674", "content_type": "video/mp4", "etag": "24c1122087e9be930ff1e957e83f5224", "last_modified": "May 21, 2024 02:55 PM" } { "key_type": "file", "key": "Samfplessss.mp4", "size": "2674", "content_type": "video/mp4", "etag": "24c1122087e9be930ff1e957e83f5224", "last_modified": "May 21, 2024 02:52 PM" } { "key_type": "file", "key": "demo.mp4", "size": "3400", "content_type": "video/mp4", "etag": "24e957e83f5224c1122087e9be930ff1", "last_modified": "May 21, 2024 02:52 PM" } { "key_type": "file", "key": "performance.mp4", "size": "1454", "content_type": "video/mp4", "etag": "087e9be930ff124c1122e957e83f5224", "last_modified": "May 21, 2024 02:52 PM" }
Last Updated 2025-06-20 16:21:48 +0530 +0530
Yes
No
Send your feedback to us