当您不再需要保留某个桶(Bucket)时,可将其删除,以免产生额外费用。
tos:DeleteBucket
权限。删除桶之前,请确保您已经删除桶中所有数据。
import { TosClient, TosClientError, TosServerError } from '@volcengine/tos_harmonyos_sdk'; // 创建客户端 const client = new TosClient({ accessKeyId: "Provide your ak', accessKeySecret: "Provide your ak", securityToken: 'Provide your securityToken', region: "Provide your region", // 填写 Bucket 所在地域。以华北2(北京)为例,"Provide your region" 填写为 cn-beijing。 endpoint: "Provide your endpoint", // 填写域名地址 }); 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); } } const bucketName = 'harmonyos-sdk-test-bucket'; async function main() { try { // 判断桶是否存在 const res = await client.deleteBucket({ Bucket: bucketName }); console.log(`the status code of delete ${bucketName} is`, res.StatusCode); } catch (error) { handleError(error); } } main();
关于删除桶的 API 文档,请参见 DeleteBucket。