文档中心 > 获取桶的地域
获取桶的地域

最近更新时间:2021-10-29

以下代码用于获取桶的地域。

using System;

using Amazon.S3;

using Amazon.S3.Model;

 

namespace GetBucketLocation

{

    class Program

    {

        static void Main(string[] args)

        {  

            var Ak = "xxx";

            var Sk = "xxx";

            var endpoint = "http://s3.test.com";

            AmazonS3Client serviceClient = new AmazonS3Client(Ak,Sk,

            new AmazonS3Config{ ServiceURL = endpoint });

 

            try

            {  

                GetBucketLocationResponse resp;

                GetBucketLocationRequest request = new GetBucketLocationRequest

                {

                    BucketName = "xxx"

                };

                

            // Issue call

            resp = serviceClient.GetBucketLocationAsync(request).GetAwaiter().GetResult();

           

            // View response data

            Console.WriteLine("Bucket location - {0}", resp.Location);

            

            } catch (AmazonS3Exception e) {

                Console.WriteLine(e.Message);

                throw;

            } catch (Exception e) {

                Console.WriteLine(e);

                throw;

            }

 

        }

 

    }

}