Exemplo n.º 1
0
        public void Delete(string remotename)
        {
            try
            {
                cosXml = GetCosXml();
                string bucket = _cosOptions.Bucket;
                string key    = GetFullKey(remotename);

                DeleteObjectRequest request = new DeleteObjectRequest(bucket, key);

                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                DeleteObjectResult result = cosXml.DeleteObject(request);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Logging.Log.WriteErrorMessage(LOGTAG, "Delete", clientEx, "Delete failed: {0}", remotename);
                throw;
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Logging.Log.WriteErrorMessage(LOGTAG, "Delete", serverEx, "Delete failed: {0}, {1}", remotename, serverEx.GetInfo());
                throw;
            }
        }
Exemplo n.º 2
0
        public bool DeleteObject(string key)
        {
            try
            {
                DeleteObjectRequest request = new DeleteObjectRequest(options.Bucket, key);
                //执行请求
                DeleteObjectResult result = cosXml.DeleteObject(request);
                //请求成功
                // Console.WriteLine(result.GetResultInfo());

                logger.LogInformation($"DeleteObject[{key}]:{result.GetResultInfo()}");
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                logger.LogError(clientEx, $"DeleteObject");
                return(false);
                //请求失败
                //Console.WriteLine("CosClientException: " + clientEx);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                logger.LogError(serverEx, $"DeleteObject");
                return(false);
                //请求失败
                // Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }

            return(true);
        }
Exemplo n.º 3
0
        /// 删除对象
        public void DeleteObject()
        {
            //.cssg-snippet-body-start:[delete-object]
            try
            {
                string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
                string key    = "exampleobject";            //对象键
                DeleteObjectRequest request = new DeleteObjectRequest(bucket, key);
                //执行请求
                DeleteObjectResult result = cosXml.DeleteObject(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
        }
        public async Task <bool> RemoveObjectAsync(string bucketName, string objectName)
        {
            if (string.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentNullException(nameof(bucketName));
            }
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }
            bucketName = ConvertBucketName(bucketName);
            DeleteObjectRequest request = new DeleteObjectRequest(bucketName, objectName);
            DeleteObjectResult  result  = _client.DeleteObject(request);

            return(await Task.FromResult(result.IsSuccessful()));
        }
Exemplo n.º 5
0
        /// 移动对象
        public async void MoveObject()
        {
            TransferConfig transferConfig = new TransferConfig();

            // 初始化 TransferManager
            TransferManager transferManager = new TransferManager(cosXml, transferConfig);

            //.cssg-snippet-body-start:[move-object]
            string sourceAppid  = "1250000000";              //账号 appid
            string sourceBucket = "sourcebucket-1250000000"; //"源对象所在的存储桶
            string sourceRegion = "COS_REGION";              //源对象的存储桶所在的地域
            string sourceKey    = "sourceObject";            //源对象键
            //构造源对象属性
            CopySourceStruct copySource = new CopySourceStruct(sourceAppid, sourceBucket,
                                                               sourceRegion, sourceKey);

            string bucket = "examplebucket-1250000000"; //目标存储桶,格式:BucketName-APPID
            string key    = "exampleobject";            //目标对象的对象键

            COSXMLCopyTask copyTask = new COSXMLCopyTask(bucket, key, copySource);

            try {
                // 拷贝对象
                COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = await
                                                                       transferManager.CopyAsync(copyTask);

                Console.WriteLine(result.GetResultInfo());

                // 删除对象
                DeleteObjectRequest request      = new DeleteObjectRequest(sourceBucket, sourceKey);
                DeleteObjectResult  deleteResult = cosXml.DeleteObject(request);
                // 打印结果
                Console.WriteLine(deleteResult.GetResultInfo());
            } catch (Exception e) {
                Console.WriteLine("CosException: " + e);
            }
            //.cssg-snippet-body-end
        }