Ejemplo n.º 1
0
        /// 获取存储桶信息
        public void HeadBucket()
        {
            //.cssg-snippet-body-start:[head-bucket]
            try
            {
                string            bucket  = "examplebucket-1250000000"; //格式:BucketName-APPID
                HeadBucketRequest request = new HeadBucketRequest(bucket);
                //执行请求
                HeadBucketResult result = cosXml.HeadBucket(request);
                //请求成功
                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                //请求失败
                Console.WriteLine("CosClientException: " + clientEx);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                //请求失败
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }

            //.cssg-snippet-body-end
        }
Ejemplo n.º 2
0
        public void Test()
        {
            var json = JsonConvert.SerializeObject(_cosOptions);

            try
            {
                cosXml = GetCosXml();
                string            bucket  = _cosOptions.Bucket;
                HeadBucketRequest request = new HeadBucketRequest(bucket);
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
                HeadBucketResult result = cosXml.HeadBucket(request);

                Logging.Log.WriteInformationMessage(LOGTAG, "Test", "Request complete {0}: {1}, {2}", result.httpCode, json, result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Logging.Log.WriteErrorMessage(LOGTAG, "Test", clientEx, "Request failed: {0}", json);
                throw;
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Logging.Log.WriteErrorMessage(LOGTAG, "Test", serverEx, "Request failed: {0}, {1}", json, serverEx.GetInfo());
                throw;
            }
        }
Ejemplo n.º 3
0
        public Task <bool> BucketExistsAsync(string bucketName)
        {
            if (string.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentNullException(nameof(bucketName));
            }
            bucketName = ConvertBucketName(bucketName);
            HeadBucketRequest request = new HeadBucketRequest(bucketName);

            try
            {
                HeadBucketResult result = _client.HeadBucket(request);
                return(Task.FromResult(true));
            }
            catch (COSXML.CosException.CosClientException ex)
            {
                throw new Exception($"Rquest client error, {ex.Message}", ex);
            }
            catch (COSXML.CosException.CosServerException ex)
            {
                if (ex.statusCode == 403)
                {
                    return(Task.FromResult(true));
                }
                else if (ex.statusCode == 404)
                {
                    return(Task.FromResult(false));
                }
                else
                {
                    throw new Exception($"Server error, {ex.Message}", ex);
                }
            }
        }