This document provides an overview of APIs and SDK code samples related to basic bucket operations.
API | Operation | Description |
---|---|---|
HEAD Bucket | Checking a bucket and its permissions | Checks whether a bucket exists and whether you have permission to access it |
DELETE Bucket | Deleting a bucket | Deletes an empty bucket from a specified account |
This API is used to verify whether a bucket exists and whether you have permission to access it.
Extracting bucket information:
cos.headBucket({
Bucket: 'examplebucket-1250000000', /* Required */
Region: 'COS_REGION', /* Bucket region. Required */
}, function(err, data) {
console.log(err || data);
});
Determining whether the bucket exists:
function doesBucketExist() {
cos.headBucket({
Bucket: 'examplebucket-1250000000', /* Required */
Region: 'COS_REGION', /* Bucket region. Required */
}, function(err, data) {
if (data) {
console.log('The bucket exists.');
} else if (err.code == 404) {
console.log('The bucket does not exist.');
} else if (err.code == 403) {
console.log('no permission to read the bucket');
}
});
}
Parameter | Description | Type | Required |
---|---|---|---|
Bucket | Bucket name in the format of BucketName-APPID . |
String | Yes |
Region | Bucket region. For the enumerated values, please see Regions and Access Endpoints. | String | Yes |
function(err, data) { ... }
Parameter Name | Description | Type |
---|---|---|
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, please see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Headers | Object |
data | Content 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 | Headers | Object |
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, please make sure that all the data and incomplete multipart uploads in the bucket have been cleared; otherwise, the bucket cannot be deleted.
cos.deleteBucket({
Bucket: 'examplebucket-1250000000', /* Required */
Region: 'COS_REGION', /* Bucket region. Required */
}, function(err, data) {
console.log(err || data);
});
Parameter | Description | Type | Required |
---|---|---|---|
Bucket | Bucket name in the format of BucketName-APPID . |
String | Yes |
Region | Bucket region. For the enumerated values, please see Regions and Access Endpoints. | String | Yes |
function(err, data) { ... }
Parameter Name | Description | Type |
---|---|---|
err | Object returned when an error (network error or service error) occurs. If the request is successful, this parameter is left empty. For more information, please see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Headers | Object |
data | Content 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 | Headers | Object |
Was this page helpful?