文档中心 > 获取文件的访问权限
获取文件的访问权限

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

以下代码用于获取文件的访问权限。

using System;

using Amazon.S3;

using Amazon.S3.Model;

 

namespace GetACL

{

    class Program

    {

        static void Main()

        {  

            var Ak = "xxx";

            var Sk = "xxx";

            var endpoint = "xxx";

            AmazonS3Client serviceClient = new AmazonS3Client(Ak,Sk,

            new AmazonS3Config{ ServiceURL = endpoint });

 

            try

            {  

                GetACLResponse response;

                GetACLRequest getObject = new GetACLRequest{

                    BucketName = "xxx",

                    Key = "xxx",  // object name

                };

 

                response = serviceClient.GetACLAsync(getObject).GetAwaiter().GetResult();

                Console.WriteLine("Owner is :{0}", response.AccessControlList.Owner.DisplayName);

               

                foreach (S3Grant g_value in response.AccessControlList.Grants)

                {

                    Console.WriteLine("Permission: {0}", g_value.Permission);

                }

            

            } catch (AmazonS3Exception e) {

                Console.WriteLine(e.Data);

                throw;

            } catch (Exception e) {

                Console.WriteLine(e);

                throw;

            }

        }

    }

}