文档中心 > 设置文件的访问权限
设置文件的访问权限

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

桶(Bucket)是存储对象(Object)的容器。对象都隶属于桶。

对象ACL权限说明:

权限

访问权限

S3CannedACL.Private

私有

S3CannedACL.PublicRead

公共读

S3CannedACL.PublicReadWrite

公共读写

 

以下代码用于设置文件的访问权限。

using System;

using Amazon.S3;

using Amazon.S3.Model;

 

namespace PutACL

{

    class Program

    {

        static void Main()

        {  

             var Ak = "xxx";

            var Sk = "xxx";

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

            AmazonS3Client serviceClient = new AmazonS3Client(Ak,Sk,

            new AmazonS3Config{ ServiceURL = endpoint });

 

            try

            {  

                PutACLResponse response;

                PutACLRequest putObject = new PutACLRequest{

                    BucketName = "xxx",

                    Key = "xxx",  // object name

                    // S3CannedACL.Private 私有

                    CannedACL = S3CannedACL.Private

                };

 

                response = serviceClient.PutACLAsync(putObject).GetAwaiter().GetResult();

                Console.WriteLine(response.HttpStatusCode);

            

            } catch (AmazonS3Exception e) {

                Console.WriteLine(e.Data);

                throw;

            } catch (Exception e) {

                Console.WriteLine(e);

                throw;

            }

        }

    }

}