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

Querying a Bucket List

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-08-15 16:30:18

Overview

This document provides an API overview and SDK example code for querying the bucket list.

Notes

Before using bucket-related operations, you must have relevant permissions. Specifically:
To query the bucket list, when you perform authorization policy, set the action to cos:GetService. For more authorization, see CAM-Enabled API.

Related Examples

Feature Name
Description
Sample code
Querying the Bucket List
Query the list of all buckets under a specified account.

Querying the Bucket List

Feature Overview

Query the list of all buckets under a specified account.

Method Prototype

func (s *ServiceService) Get(ctx context.Context, opt ...*ServiceGetOptions) (*ServiceGetResult, *Response, error)

Request Example

package main

import (
"context"
"fmt"
"github.com/tencentyun/cos-go-sdk-v5"
"net/http"
"net/url"
"os"
)

func main() {
// Bucket name, composed of bucketname-appid. The appid must be entered. You can view the bucket name in the COS console. https://console.tencentcloud.com/cos5/bucket
// Replace with the user's region. The bucket region can be viewed in the "bucket overview" section of the COS console https://console.tencentcloud.com/. For details about regions, see https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.
u, _ := url.Parse("https://examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com")
su, _ := url.Parse("https://service.cos.myqcloud.com")
// If only calling the GetService API, you only need to configure ServiceURL. The SDK internally sets ServiceURL to https://service.cos.myqcloud.com by default.
b := &cos.BaseURL{BucketURL: u, ServiceURL: su}
client := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
// Get key through environment variables
// The environment variable SECRETID means the user's SecretId. View the key in the Cloud Access Management console at https://console.tencentcloud.com/cam/capi.
SecretID: os.Getenv("SECRETID"), // User's SecretId. It is recommended to use sub-account keys and follow the principle of least privilege to reduce usage risks. For obtaining sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1.
// The environment variable SECRETKEY means the user's SecretKey. View the key in the CAM console at https://console.tencentcloud.com/cam/capi.
SecretKey: os.Getenv("SECRETKEY"), // User's SecretKey. It is recommended to use sub-account keys and follow the principle of least privilege to reduce usage risks. For obtaining sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1.
},
})
res, _, err := client.Service.Get(context.Background())
if err != nil {
panic(err)
}
for _, bucket := range res.Buckets {
fmt.Printf("%+v\\n", bucket)
}
}

Parameter Description

type ServiceGetOptions struct {
TagKey string
TagValue string
MaxKeys int64
Marker string
Range string
CreateTime int64
Region string
}
Parameter Name
Parameter Description
Type
Required or Not
TagKey
Filter buckets based on bucket tags (composed of tag key and tag value). Only one bucket tag is supported. Use tagkey to input the tag key. If querying buckets by bucket tag, both tagkey and tagvalue are required.
string
No
TagValue
Filter buckets by bucket tags (consisting of tag key and tag value). Only one bucket tag is supported. Use tagvalue to input the tag value. If querying buckets by bucket tag, both tagkey and tagvalue are required.
string
No
MaxKeys
The maximum number of entries returned at a time is 2000 by default, with a maximum of 2000. If the single response does not list all buckets, COS returns a NextMarker node, whose value serves as the marker parameter for the next GetService request.
int
No
Marker
Starting marker, starting from which (excluding), bucket entries are returned in UTF-8 lexicographical order.
string
No
Range
Used with the create-time parameter, it supports time filtering for buckets based on creation time. Supported enumeration values: lt (creation time earlier than create-time), gt (creation time later than create-time), lte (creation time earlier than or equal to create-time), gte (creation time later than or equal to create-time).
string
No
CreateTime
GMT timestamp, used with the range parameter, supports filtering buckets based on creation time, for example create-time=1642662645
int
No
Region
Filter buckets based on region, for example region=ap-beijing
string
No

Return Result Description

The request result is returned through GetServiceResult.
type ServiceGetResult struct {
Owner *Owner
Buckets []Bucket
}
type Owner struct {
ID string
DisplayName string
}
type Bucket struct {
Name string
Region string
CreationDate string
}
Parameter Name
Parameter Description
Type
ID
ID of the bucket owner.
string
DisplayName
Name of the bucket owner.
string
Name
Bucket
string
Region
Region of the Bucket
string
CreationDate
Bucket creation time in ISO 8601 format. Example: 2019-05-24T10:56:40Z.
string

API Operations

For the API interface description of querying the bucket list, please refer to the GET Service (List Buckets) document.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan