List Objects in a Bucket

List all Objects by Pagination

This SDK method will allow you to get a list of all the objects present in a particular bucket by pagination. The Bucket reference used in the below code snippet is the component instance.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

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
maxKey String A Mandatory parameter. Will contain the maximum limit of objects that can be listed by pagination.
nextToken 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 maxKey. 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 keys: 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
  • continuation_token: If you a sent a continuation_token in the request, it will be shown in the response.
  • next_continuation_token: If the response was truncated, the value of this key must be passed as continuation_token to the same method for retrieving the next set of objects.

With each iteration, we will list the maxKey number of objects and check if nextToken has been created. Using nextToken we will continue the iteration till all the objects have been listed.

    
copy
// List all the objects in the bucket by pagination async function listMyPaginatedObjects(maxKey = null, prefix = null, nextToken = null) { const objects = await bucket.listPagedObjects({ maxKeys, prefix, continuationToken: nextToken }); // return the max key number of objects console.log(objects); if (objects.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. listMyPaginatedObjects(maxKey, prefix, objects.next_continuation_token) // get the next set of objects } } await listMyPaginatedObjects(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 list all the objects present in a bucket in a single API call, using iteration technique. Using the maxKey variable, you can access the required number of objects.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section
    
copy
// access the objects by itreration logics const files = bucket.listIterableObjects({maxKeys: 5, prefix: 'sam'}); for await (const file of files) { console.log('file:', file); }

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