文档中心 > 创建桶
创建桶

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

以下代码用于创建桶。

using System;

using Amazon.S3;

using Amazon.S3.Model;

 

namespace Createbucket

{

    class Program

    {

        static void Main(string[] args)

        {  

            var Ak = "";

            var Sk = "";

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

            var bucketName = "";

 

            AmazonS3Client serviceClient = new AmazonS3Client(Ak,Sk,

            new AmazonS3Config{ ServiceURL = endpoint });

 

            try

            {  

                PutBucketResponse resp;

                // Construct request

                PutBucketRequest request = new PutBucketRequest

                {

                    BucketName = bucketName,

                };

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

                Console.WriteLine(resp.HttpStatusCode);

 

            

            } catch (AmazonS3Exception e) {

                Console.WriteLine(e.Message);

                throw;

            } catch (Exception e) {

                Console.WriteLine(e);

                throw;

            }

 

        }

 

    }

}