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.
<meta charset="UTF-8" />
<button id="upload">Upload</button>
<input id="file" type="file" />
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>
<script type="text/javascript">
const client = new TOS({
accessKeyId: yourAccessKey,
accessKeySecret: yourSecretKey,
stsToken: yourSecurityToken,
console.log(`listObjects bucketName:${examplebucket} data: `, data);
Paginated Listing
The following code is used to list objects in the specified bucket with pagination.
<meta charset="UTF-8" />
<button id="upload">Upload</button>
<input id="file" type="file" />
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>
<script type="text/javascript">
const client = new TOS({
accessKeyId: yourAccessKey,
accessKeySecret: yourSecretKey,
stsToken: yourSecurityToken,
const listObjects = async () => {
const { data } = await client.listObjects({
console.log('firstPage', data);
const secondPage = await client.listObjects({
marker: data.NextMarker,
console.log('secondPage', secondPage.data);
List all objects with the specified prefix
The following code is used to list all objects in the bucket with the specified prefix.
<meta charset="UTF-8" />
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>
<script type="text/javascript">
const client = new TOS({
accessKeyId: yourAccessKey,
accessKeySecret: yourSecretKey,
stsToken: yourSecurityToken,
const listObjects = async () => {
const data = await client.listObjects({
console.log('data', data.data);
List all objects in the bucket
The following code enumerates all objects within the specified storage bucket.
<meta charset="UTF-8" />
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>
<script type="text/javascript">
const client = new TOS({
accessKeyId: yourAccessKey,
accessKeySecret: yourSecretKey,
stsToken: yourSecurityToken,
const listObjects = async () => {
const data = await client.listObjects({
console.log('data', data.data);
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.
<meta charset="UTF-8" />
<button id="upload">Upload</button>
<input id="file" type="file" />
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>
<script type="text/javascript">
const client = new TOS({
accessKeyId: yourAccessKey,
accessKeySecret: yourSecretKey,
stsToken: yourSecurityToken,
const listObjects = async () => {
const data = await client.listObjects({
delimiter: 'example_dir',
console.log('data', data.data);