tencent cloud

All product documents
Cloud Object Storage
Querying a Bucket List
Last updated: 2024-02-02 14:36:36
Querying a Bucket List
Last updated: 2024-02-02 14:36:36

Overview

This document provides an overview of APIs and SDK code samples related to how to query a bucket list.
API
Operation
Description
Querying a bucket list
Queries the list of all buckets under a specified account

Querying a Bucket List

Description

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

Sample code

using COSXML.Model.Tag;
using COSXML.Model.Service;
using COSXML.Auth;
using System;
using COSXML;
using System.Collections.Generic;

namespace COSSnippet
{
public class GetServiceModel {

private CosXml cosXml;

GetServiceModel() {
CosXmlConfig config = new CosXmlConfig.Builder()
.SetRegion("COS_REGION") // Set the default region. For abbreviations of COS regions, visit https://cloud.tencent.com/document/product/436/6224.
.Build();

string secretId = "SECRET_ID"; // SecretId of the TencentCloud API. For more information about how to obtain the API key, see https://console.cloud.tencent.com/cam/capi.
string secretKey = "SECRET_KEY"; // SecretKey of the TencentCloud API. For more information about how to obtain the API key, see https://console.cloud.tencent.com/cam/capi.
long durationSecond = 600; // Validity period of the request signature in seconds
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,
secretKey, durationSecond);

this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);
}

/// Get the bucket list.
public void GetService()
{
//.cssg-snippet-body-start:[get-service]
try
{
GetServiceRequest request = new GetServiceRequest();
// Execute the request
GetServiceResult result = cosXml.GetService(request);
// Get the list of all buckets.
List<ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets;
}
catch (COSXML.CosException.CosClientException clientEx)
{
// Request failed
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
// Request failed
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

//.cssg-snippet-body-end
}

/// Get the list of buckets residing in this region.
public void GetRegionalService()
{
//.cssg-snippet-body-start:[get-regional-service]
try
{
GetServiceRequest request = new GetServiceRequest();
string region = "ap-guangzhou";
request.host = $"cos.{region}.myqcloud.com";
// Execute the request
GetServiceResult result = cosXml.GetService(request);
// Get the list of all buckets.
List<ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets;
}
catch (COSXML.CosException.CosClientException clientEx)
{
// Request failed
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
// Request failed
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
//.cssg-snippet-body-end
}

// .cssg-methods-pragma

static void Main(string[] args)
{
GetServiceModel m = new GetServiceModel();

/// Get the bucket list.
m.GetService();
/// Get the list of buckets residing in this region.
m.GetRegionalService();
// .cssg-methods-pragma
}
}
}

Note:
For the complete sample, please go to GitHub.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support