You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Bucket Interface
List Buckets (.NET SDK)
Copy page
Download PDF
List Buckets (.NET SDK)
A bucket (Bucket) in TOS serves as a globally unique namespace, functioning as a data container for storing object (Object) data. This article describes how to use the TOS .NET SDK listBuckets interface to enumerate all storage buckets under the current account across all regions that meet specified criteria.​
Notes​
  • Before listing buckets, you must ensure that your account has the tos:ListBuckets permission. For detailed instructions, please refer to the Permission Configuration Guide.​
  • This interface returns all buckets in every region associated with the current account.​
Sample Code​
The following code enumerates all buckets across all regions for the current account.​
​
using System;​
using TOS;​
using TOS.Error;​
​
namespace ConsoleApp​
{​
internal class Program​
{​
private static void Main(string[] args)​
{​
var ak = Environment.GetEnvironmentVariable("TOS_ACCESS_KEY");​
var sk = Environment.GetEnvironmentVariable("TOS_SECRET_KEY");​
var endpoint = "https://tos-cn-beijing.volces.com";​
var region = "cn-beijing";​
​
var client = TosClientBuilder.Builder().SetAk(ak).SetSk(sk).SetEndpoint(endpoint).SetRegion(region).Build();​
​
try​
{​
var listBucketsOutput = client.ListBuckets();​
Console.WriteLine("List bucket succeeded, request id {0} ", listBucketsOutput.RequestID);​
Console.WriteLine("List bucket succeeded, status code {0} ", listBucketsOutput.StatusCode);​
foreach (var bucket in listBucketsOutput.Buckets)​
{​
Console.WriteLine("Bucket Name: {0}", bucket.Name);​
Console.WriteLine("Bucket CreationDate: {0}", bucket.CreationDate);​
Console.WriteLine("Bucket Location: {0}", bucket.Location);​
Console.WriteLine("Bucket ExtranetEndpoint: {0}", bucket.ExtranetEndpoint);​
Console.WriteLine("Bucket IntranetEndpoint: {0}", bucket.IntranetEndpoint);​
}​
}​
catch (TosServerException ex)​
{​
Console.WriteLine("List bucket failed, request id {0}", ex.RequestID);​
Console.WriteLine("List bucket failed, status code {0}", ex.StatusCode);​
Console.WriteLine("List bucket failed, response error code {0}", ex.Code);​
Console.WriteLine("List bucket failed, response error message {0}", ex.Message);​
}​
catch (TosClientException ex)​
{​
Console.WriteLine("List bucket failed, error message {0}", ex.Message);​
}​
catch (Exception ex)​
{​
Console.WriteLine("List bucket failed, {0}", ex.Message);​
}​
}​
}​
}​
​
Related documentation​
For a detailed introduction to the API interface for listing buckets, see ListBuckets.​
Last updated: 2025.09.23 11:28:04