Esempio n. 1
0
 /// 完成分片上传任务
 private void CompleteMultiUpload()
 {
     try
     {
         CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(bucket, key, uploadId);
         //设置已上传的parts,必须有序,按照partNumber递增
         Dictionary <int, string> partNumberAndETags_SortedByKey = partNumberAndETags.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
         request.SetPartNumberAndETag(partNumberAndETags_SortedByKey);
         //执行请求
         CompleteMultipartUploadResult result = cosXml.CompleteMultiUpload(request);
         //请求成功
         //Console.WriteLine(result.GetResultInfo());
     }
     catch (ArgumentNullException e)
     {
         InfoLog.InfoPrintf($"Cos: ArgumentNullException: {e}", InfoLog.InfoClass.系统错误信息);
     }
     catch (COSXML.CosException.CosClientException clientEx)
     {
         //请求失败
         InfoLog.InfoPrintf($"Cos: CosClientException: {clientEx}", InfoLog.InfoClass.系统错误信息);
     }
     catch (COSXML.CosException.CosServerException serverEx)
     {
         //请求失败
         InfoLog.InfoPrintf($"Cos: CosServerException: {serverEx.GetInfo()}", InfoLog.InfoClass.系统错误信息);
     }
 }
        /// 完成分片拷贝任务
        public void CompleteMultiUpload()
        {
            //.cssg-snippet-body-start:[complete-multi-upload]
            try
            {
                string bucket   = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
                string key      = "exampleobject";            //对象键
                string uploadId = "exampleUploadId";          //初始化分块上传返回的uploadId
                CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(bucket,
                                                                                            key, uploadId);
                //设置已上传的parts,必须有序,按照partNumber递增
                request.SetPartNumberAndETag(1, this.eTag);
                //执行请求
                CompleteMultipartUploadResult result = cosXml.CompleteMultiUpload(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
        }