Feature Overview
This document provides an overview of APIs and SDK code samples related to basic bucket operations.
API | Operation | Description |
Checking a bucket and its permission | Checks whether a bucket exists and you have permission to access it | |
Deleting a bucket | Deletes an empty bucket under a specified account |
Checking a bucket and its permission
Note
This API (
HEAD Bucket) is used to verify whether a bucket exists and whether you have permission to access it.If the bucket exists and you have permission to read it, HTTP status code 200 will be returned.
If you do not have permission to read the bucket, HTTP status code 403 will be returned.
If the bucket does not exist, HTTP status code 404 will be returned.
Use Cases
Extracting bucket information:
cos.headBucket({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */}, function(err, data) {console.log(err || data);});
Determining whether the bucket exists:
function doesBucketExist() {cos.headBucket({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */}, function(err, data) {if (data) {console.log('Bucket exists');} else if (err.statusCode == 403) {console.log('No read permission for this bucket');}});}
Description
Parameter | ParameterDescription | Local Disk Types | Required |
Bucket | Bucket name in the format of BucketName-APPID | String | Required |
Region | String | Required |
Callback function description
function(err, data) { ... }
Parameter | ParameterDescription | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | Returns an HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Object returned when the request is successful. If the request fails, this parameter is empty. | Object |
- statusCode | Returns an HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
Deleting a bucket
Note
This API is used to delete an empty bucket under a specified account. Note that if the deletion is successful, the HTTP status code 200 or 204 will be returned.
Note
Before deleting a bucket, make sure that all the data and incomplete multipart uploads in the bucket have been cleared; otherwise, the bucket cannot be deleted.
Use Cases
cos.deleteBucket({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */}, function(err, data) {console.log(err || data);});
Description
Parameter | ParameterDescription | Local Disk Types | Required |
Bucket | Bucket name in the format of BucketName-APPID | String | Required |
Region | Bucket region. For the enumerated values, see Regions and Access Domain Names | String | Required |
Callback function description
function(err, data) { ... }
Parameter | ParameterDescription | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Object returned when the request is successful. If the request fails, this parameter is empty. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |