You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Basic Bucket Interface
Enumerate Buckets (Harmony SDK)
Copy page
Download PDF
Enumerate Buckets (Harmony SDK)
Obtain the list of storage buckets (Bucket) using ListBuckets. You can list all storage buckets under all regions of the current account that meet the specified criteria.​
Precautions​
  • Before listing buckets, you must have the tos:ListBuckets permission.​
  • The ListBuckets API returns all buckets in all regions for the current account.​
Sample Code​
The following code is used to list all buckets across all regions for the current account.​
​
import { TosClient, TosClientError, TosServerError } from '@volcengine/tos_harmonyos_sdk';​
​
​
const client = new TosClient({​
accessKeyId: "Provide your ak",​
accessKeySecret: "Provide your sk",​
securityToken: 'Provide your securityToken',​
region: "Provide your region", ​
endpoint: "Provide your endpoint", ​
});​
​
const bucketName = 'harmonyos-sdk-test-bucket';​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
console.log('Client Err Msg:', error.message);​
console.log('Client Err Stack:', error.stack);​
} else if (error instanceof TosServerError) {​
console.log('Request ID:', error.requestId);​
console.log('Response Status Code:', error.statusCode);​
console.log('Response Header:', error.headers);​
console.log('Response Err Code:', error.code);​
console.log('Response Err Msg:', error.message);​
} else {​
console.log('unexpected exception, message: ', error);​
}​
}​
​
async function main () {​
try {​
const res = await client.listBuckets();​
for (const bkt of res.Buckets) {​
console.log('the bucket name is: ', bkt.Name)​
}​
} catch (error) {​
handleError(error);​
}​
}​
main();​
​
Relevant Documentation​
For API documentation on listing buckets, see ListBuckets.​
Last updated: 2025.09.26 19:05:14