예제 #1
0
        /// <summary>
        /// 获取存储空间ACL的值
        /// </summary>
        public MessageRecorder <IList <Permission> > GetBucketAcl()
        {
            var r = new MessageRecorder <IList <Permission> >();

            try
            {
                var result = _client.GetBucketAcl(BucketName);
                r.Value = result.Grants.Select(m => m.Permission).ToList();
                return(r);
            }
            catch (Exception ex)
            {
                return(r.Error($"获取存储空间权限失败. 原因:{ex.Message}"));
            }
        }
예제 #2
0
 /// <summary>
 /// 获取存储空间ACL的值
 /// </summary>
 private static void GetBucketAcl()
 {
     try
     {
         var result = _client.GetBucketAcl(_bucketName);
         foreach (var grant in result.Grants)
         {
             Console.WriteLine("获取存储空间权限成功,当前权限:{0}", grant.Permission.ToString());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("获取存储空间权限失败.原因: {0}", ex.Message);
     }
 }
        /// <summary>
        /// Get Bucket Acl
        /// </summary>
        /// <returns></returns>
        public CannedAccessControlList GetBucketAcl()
        {
            AccessControlList       acl        = null;
            CannedAccessControlList accessType = CannedAccessControlList.Default;

            try
            {
                acl        = client.GetBucketAcl(bucketName);
                accessType = acl.ACL;
            }
            catch (OssException ex)
            {
                lastError = ex;
            }
            return(accessType);
        }
예제 #4
0
        /// <summary>
        /// 获取储存桶的访问权限
        /// </summary>
        /// <param name="bucketName"></param>
        /// <param name="objectName"></param>
        /// <returns></returns>
        public Task <AccessMode> GetBucketAclAsync(string bucketName)
        {
            if (string.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentNullException(nameof(bucketName));
            }
            var result = _client.GetBucketAcl(bucketName);
            var mode   = result.ACL switch
            {
                CannedAccessControlList.Default => AccessMode.Default,
                CannedAccessControlList.Private => AccessMode.Private,
                CannedAccessControlList.PublicRead => AccessMode.PublicRead,
                CannedAccessControlList.PublicReadWrite => AccessMode.PublicReadWrite,
                _ => AccessMode.Default,
            };

            return(Task.FromResult(mode));
        }
 public static void GetBucketAcl(string bucketName)
 {
     try
     {
         var result = client.GetBucketAcl(bucketName);
         Console.WriteLine("Get Bucket Acl succeeded,Id:{0} Acl:{1} succeeded",
                           result.Owner.Id, result.ACL.ToString());
     }
     catch (OssException ex)
     {
         Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                           ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Failed with error info: {0}", ex.Message);
     }
 }
예제 #6
0
        public async Task <CannedAccessControlList> getBucketAcl(string bucketName)
        {
            AccessControlList accessControlList = await _ossClient.GetBucketAcl(bucketName);

            if (accessControlList.Grants != null && accessControlList.Grants.Count() != 0)
            {
                if (accessControlList.Grants.First().Permission == Permission.Read)
                {
                    return(CannedAccessControlList.PublicRead);
                }
                if (accessControlList.Grants.First().Permission == Permission.FullControl)
                {
                    return(CannedAccessControlList.PublicReadWrite);
                }
            }

            return(CannedAccessControlList.Private);
        }
        //获取存储空间的访问权限
        public void GetBucketAcl()
        {
            var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

            try
            {
                var acl = client.GetBucketAcl("igets");
                Console.WriteLine("成功获取权限");
                foreach (var grant in acl.Grants)
                {
                    Console.WriteLine("获取存储空间权限成功,当前权限:{0}", grant.Permission.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Get bucket ACL failed. {0}", ex.Message);
            }
        }
예제 #8
0
        public static void GetBucketAcl(string bucketName)
        {
            try
            {
                var result = client.GetBucketAcl(bucketName);

                foreach (var grant in result.Grants)
                {
                    Console.WriteLine("Get Bucket Acl succeeded,Id:{0} Acl:{1} succeeded",
                                      grant.Grantee.Identifier.ToString(), grant.Permission.ToString());
                }
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
예제 #9
0
 public string GetURL(string strEndPoint, string strAccessID, string strAccessKey, string strBucketName, string strFullName)
 {
     try
     {
         string            strURL    = string.Empty;
         OssClient         ossClient = new OssClient(strEndPoint, strAccessID, strAccessKey);
         AccessControlList accs      = ossClient.GetBucketAcl(strBucketName);
         if (!accs.Grants.Any())                                                                                           //判断是否有读取权限
         {
             strURL = ossClient.GeneratePresignedUri(strBucketName, strFullName, DateTime.Now.AddMinutes(10)).AbsoluteUri; //生成一个签名的Uri 有效期5分钟
         }
         else
         {
             strURL = string.Format("http://{0}.oss.aliyuncs.com/{1}", strBucketName, strFullName);
         }
         return(strURL);
     }
     catch
     {
         throw;
     }
 }