This article describes how to list objects within a specified bucket and objects with a specified prefix, with a default maximum return of 1,000 objects.
Feature description
You can use listObjects to enumerate object information within a bucket, with a maximum of 1,000 objects returned per request. When using listObjects to list objects, owner information is returned by default. The parameters are described below:
Notes
- To prevent exposure of your Volcano Engine account credentials (namely, AccessKey ID and AccessKey Secret) in browser environments, it is strongly recommended that you perform TOS-related operations using temporary access credentials. For detailed instructions, please refer to Using STS Temporary AK/SK+Token to Access Volcano Engine TOS.
- The Endpoint is the access domain name for TOS external services. For information on endpoints supported by TOS, please refer to Endpoint Domain.
Sample Code
Brief Enumeration
The following code is used to list 10 objects in the specified bucket.
Paginated Listing
The following code is used to list objects in the specified bucket with pagination.
List all objects with the specified prefix
The following code is used to list all objects in the bucket with the specified prefix.
List all objects in the bucket
The following code enumerates all objects within the specified storage bucket.
List files and subdirectories in the specified directory
TOS recognizes only the concept of objects; it is possible to create an object with a size of zero and a slash./The object at the end simulates the functionality of a directory. The functionality of a directory can be simulated using the delimiter and prefix parameters:
- First, set delimiter to/At the same time, when prefix is set to empty, objects and subdirectory information in the root directory can be returned.
- When setting delimiter to/Additionally, setting prefix as a subdirectory (subfiledir) allows you to return objects and subdirectories within it.
The following code is used to list the objects and subdirectories within a specified directory of the bucket.