tencent cloud

Cloud Object Storage

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Use Cases
Strengths
Concepts
Regions and Access Endpoints
Specifications and Limits
Service Regions and Service Providers
Billing
Billing Overview
Billing Method
Billable Items
Free Tier
Billing Examples
Viewing and Downloading Bill
Payment Overdue
FAQs
Getting Started
Console
Getting Started with COSBrowser
User Guide
Creating Request
Bucket
Object
Data Management
Batch Operation
Global Acceleration
Monitoring and Alarms
Operations Center
Data Processing
Content Moderation
Smart Toolbox
Data Processing Workflow
Application Integration
User Tools
Tool Overview
Installation and Configuration of Environment
COSBrowser
COSCLI (Beta)
COSCMD
COS Migration
FTP Server
Hadoop
COSDistCp
HDFS TO COS
GooseFS-Lite
Online Tools
Diagnostic Tool
Use Cases
Overview
Access Control and Permission Management
Performance Optimization
Accessing COS with AWS S3 SDK
Data Disaster Recovery and Backup
Domain Name Management Practice
Image Processing
Audio/Video Practices
Workflow
Direct Data Upload
Content Moderation
Data Security
Data Verification
Big Data Practice
COS Cost Optimization Solutions
Using COS in the Third-party Applications
Migration Guide
Migrating Local Data to COS
Migrating Data from Third-Party Cloud Storage Service to COS
Migrating Data from URL to COS
Migrating Data Within COS
Migrating Data Between HDFS and COS
Data Lake Storage
Cloud Native Datalake Storage
Metadata Accelerator
GooseFS
Data Processing
Data Processing Overview
Image Processing
Media Processing
Content Moderation
File Processing Service
File Preview
Troubleshooting
Obtaining RequestId
Slow Upload over Public Network
403 Error for COS Access
Resource Access Error
POST Object Common Exceptions
API Documentation
Introduction
Common Request Headers
Common Response Headers
Error Codes
Request Signature
Action List
Service APIs
Bucket APIs
Object APIs
Batch Operation APIs
Data Processing APIs
Job and Workflow
Content Moderation APIs
Cloud Antivirus API
SDK Documentation
SDK Overview
Preparations
Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Flutter SDK
Go SDK
iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
React Native SDK
Mini Program SDK
Error Codes
Harmony SDK
Endpoint SDK Quality Optimization
Security and Compliance
Data Disaster Recovery
Data Security
Cloud Access Management
FAQs
Popular Questions
General
Billing
Domain Name Compliance Issues
Bucket Configuration
Domain Names and CDN
Object Operations
Logging and Monitoring
Permission Management
Data Processing
Data Security
Pre-signed URL Issues
SDKs
Tools
APIs
Agreements
Service Level Agreement
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Bucket Operations

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2024-02-02 16:24:05

Feature Overview

This document provides an overview of APIs and SDK code samples related to basic bucket operations.
Note:
We recommend you use a temporary key as instructed in Generating and Using Temporary Keys to call the SDK for security purposes. When you apply for a temporary key, follow the Notes on Principle of Least Privilege to avoid leaking resources besides your buckets and objects.
If you must use a permanent key, we recommend you follow the Notes on Principle of Least Privilege to limit the scope of permission on the permanent key.
API
Operation
Description
Querying the bucket list
Queries the list of all buckets under a specified account
Creating a bucket
Creates a bucket under a specified account
Checking a bucket and its permissions
Checks whether a bucket exists and whether you have permission to access it
Deleting a bucket
Deletes an empty bucket under a specified account

Querying a Bucket List

Feature description

This API is used to query the list of all buckets under a specified account.

Method prototype

public List<Bucket> listBuckets() throws CosClientException, CosServiceException;

Sample request

// If you only call the “listBuckets” method, set the region to new Region("") when creating cosClient.
List<Bucket> buckets = cosClient.listBuckets();
for (Bucket bucketElement : buckets) {
String bucketName = bucketElement.getName();
String bucketLocation = bucketElement.getLocation();
}

Field description

None.

Response description

Success: A list of all bucket classes will be returned. The bucket class contains information about bucket members, location, and more.
Failure: An error (such as the bucket does not exist) occurs, throwing the "CosClientException" or "CosServiceException" exception. For more information, see Troubleshooting.

Creating a Bucket

Feature description

This API is used to create a bucket under the specified account. You can create multiple buckets under the same user account. The maximum number is 200 (regardless of region). There is no limit to the number of objects in the bucket. Bucket creation is a low-frequency operation. We recommended you create a bucket in the console and perform object operations in the SDK.

Method prototype

public Bucket createBucket(String bucketName) throws CosClientException, CosServiceException;

Sample request

String bucket = "examplebucket-1250000000"; // Bucket, formatted as BucketName-APPID
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
// Set the bucket permission to Private (private read/write). Other options include public read/private write and public read/write.
createBucketRequest.setCannedAcl(CannedAccessControlList.Private);
Bucket bucketResult = cosClient.createBucket(createBucketRequest);

Field description

Parameter
Description
Type
bucketName
Bucket name, formatted as BucketName-APPID. For more information, see Bucket Overview.
String

Response description

Success**: the bucket class, including the bucket description (bucket name, owner, and creation date).
Failure: An error (such as authentication failure) occurs, throwing the "CosClientException" or "CosServiceException" exception. For more information, see Troubleshooting.

Checking a Bucket and Its Permissions

Feature description

This API is used to check whether a bucket exists and whether you have permission to access it.

Method prototype

public boolean doesBucketExist(String bucketName)
throws CosClientException, CosServiceException;

Sample request

The bucket name entered must be in the format of `BucketName-APPID`.
String bucketName = "examplebucket-1250000000";
boolean bucketExistFlag = cosClient.doesBucketExist(bucketName);

Field description

Parameter
Description
Type
bucketName
Bucket name, formatted as BucketName-APPID. For more information, see Bucket Overview.
String

Response description

Success: returns true if the bucket exists. Otherwise, false is returned.
Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be reported. For more information, see Troubleshooting.

Deleting a Bucket

Feature description

This API is used to delete an empty bucket under a specified account.

Method prototype

public void deleteBucket(String bucketName) throws CosClientException, CosServiceException;

Sample request

The bucket name entered must be in the format of `BucketName-APPID`.
String bucketName = "examplebucket-1250000000";
cosClient.deleteBucket(bucketName);

Field description

Parameter
Description
Type
bucketName
Bucket name, formatted as BucketName-APPID. For more information, see Bucket Overview.
String

Response description

Success: No value is returned.
Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be reported. For more information, see Troubleshooting.

Ajuda e Suporte

Esta página foi útil?

comentários