Пример #1
0
        public static void InitMultiUpload(COSXML.CosXml cosXml, string bucket, string key)
        {
            try
            {
                InitMultipartUploadRequest request = new InitMultipartUploadRequest(bucket, key);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                InitMultipartUploadResult result = cosXml.InitMultipartUpload(request);

                Console.WriteLine(result.GetResultInfo());
                QLog.D("XIAO", result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                QLog.D("XIAO", clientEx.Message);
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                QLog.D("XIAO", serverEx.Message);
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }
        }
Пример #2
0
        public static void AsynInitMultiUpload(COSXML.CosXml cosXml, string bucket, string key)
        {
            QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
            InitMultipartUploadRequest request = new InitMultipartUploadRequest(bucket, key);

            //设置签名有效时长
            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

            cosXml.InitMultipartUpload(request,
                                       delegate(CosResult cosResult)
            {
                InitMultipartUploadResult result = cosResult as InitMultipartUploadResult;
                Console.WriteLine(result.GetResultInfo());
                Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
                QLog.D("XIAO", result.GetResultInfo());
            },
                                       delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    QLog.D("XIAO", clientEx.Message);
                    Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                }
                if (serverEx != null)
                {
                    QLog.D("XIAO", serverEx.Message);
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }
                Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
            });
        }
Пример #3
0
 private void InitMultiUploadPart()
 {
     initMultiUploadRequest = new InitMultipartUploadRequest(bucket, key);
     initMultiUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
     cosXmlServer.InitMultipartUpload(initMultiUploadRequest, delegate(CosResult cosResult)
     {
         lock (syncExit)
         {
             if (isExit)
             {
                 return;
             }
         }
         InitMultipartUploadResult result = cosResult as InitMultipartUploadResult;
         uploadId = result.initMultipartUpload.uploadId;
         //计算分片块
         ComputeSliceNums();
         //通知执行PartCopy
         OnInit();
     },
                                      delegate(CosClientException clientEx, CosServerException serverEx)
     {
         lock (syncExit)
         {
             if (isExit)
             {
                 return;
             }
         }
         if (UpdateTaskState(TaskState.FAILED))
         {
             OnFailed(clientEx, serverEx);
         }
     });
 }
Пример #4
0
        public void AbortMultiUpload(COSXML.CosXml cosXml, string bucket, string key, string srcPath)
        {
            try
            {
                InitMultipartUploadRequest initMultipartUploadRequest = new InitMultipartUploadRequest(bucket, key);
                //设置签名有效时长
                initMultipartUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                InitMultipartUploadResult initMultipartUploadResult = cosXml.InitMultipartUpload(initMultipartUploadRequest);

                Console.WriteLine(initMultipartUploadResult.GetResultInfo());

                string uploadId = initMultipartUploadResult.initMultipartUpload.uploadId;

                AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucket, key, uploadId);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
                //执行请求
                AbortMultipartUploadResult result = cosXml.AbortMultiUpload(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
Пример #5
0
        public void PartCopyObject(COSXML.CosXml cosXml, string bucket, string key,
                                   COSXML.Model.Tag.CopySourceStruct copySource)
        {
            try
            {
                InitMultipartUploadRequest initMultipartUploadRequest = new InitMultipartUploadRequest(bucket, key);
                //设置签名有效时长
                initMultipartUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                InitMultipartUploadResult initMultipartUploadResult = cosXml.InitMultipartUpload(initMultipartUploadRequest);

                Console.WriteLine(initMultipartUploadResult.GetResultInfo());

                string uploadId = initMultipartUploadResult.initMultipartUpload.uploadId;

                int partNumber = 1;

                UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(bucket, key, partNumber, uploadId);
                //设置签名有效时长
                uploadPartCopyRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //设置拷贝源
                uploadPartCopyRequest.SetCopySource(copySource);

                //设置拷贝范围
                uploadPartCopyRequest.SetCopyRange(0, 10);

                //执行请求
                UploadPartCopyResult uploadPartCopyResult = cosXml.PartCopy(uploadPartCopyRequest);

                Console.WriteLine(uploadPartCopyResult.GetResultInfo());

                string eTag = uploadPartCopyResult.copyObject.eTag;

                CompleteMultipartUploadRequest completeMultiUploadRequest = new CompleteMultipartUploadRequest(bucket, key, uploadId);
                //设置签名有效时长
                completeMultiUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //设置已上传的parts
                completeMultiUploadRequest.SetPartNumberAndETag(partNumber, eTag);

                //执行请求
                CompleteMultipartUploadResult completeMultiUploadResult = cosXml.CompleteMultiUpload(completeMultiUploadRequest);

                Console.WriteLine(completeMultiUploadResult.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
Пример #6
0
        public void AsynInitMultiUpload(COSXML.CosXml cosXml, string bucket, string key)
        {
            InitMultipartUploadRequest request = new InitMultipartUploadRequest(bucket, key);

            //设置签名有效时长
            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

            cosXml.InitMultipartUpload(request,
                                       delegate(CosResult cosResult)
            {
                InitMultipartUploadResult result = cosResult as InitMultipartUploadResult;
                Console.WriteLine(result.GetResultInfo());
            },
                                       delegate(CosClientException clientEx, CosServerException serverEx)
            {
                Console.WriteLine(clientEx == null ? serverEx.GetInfo() : clientEx.Message);
            });
        }
Пример #7
0
        public void MultiUpload(COSXML.CosXml cosXml, string bucket, string key, string srcPath)
        {
            try
            {
                InitMultipartUploadRequest initMultipartUploadRequest = new InitMultipartUploadRequest(bucket, key);
                //设置签名有效时长
                initMultipartUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                InitMultipartUploadResult initMultipartUploadResult = cosXml.InitMultipartUpload(initMultipartUploadRequest);

                Console.WriteLine(initMultipartUploadResult.GetResultInfo());

                string uploadId = initMultipartUploadResult.initMultipartUpload.uploadId;

                ListPartsRequest listPartsRequest = new ListPartsRequest(bucket, key, uploadId);
                //设置签名有效时长
                listPartsRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                ListPartsResult listPartsResult = cosXml.ListParts(listPartsRequest);

                Console.WriteLine(listPartsResult.GetResultInfo());

                int partNumber = 1;

                UploadPartRequest uploadPartRequest = new UploadPartRequest(bucket, key, partNumber, uploadId, srcPath);
                //设置签名有效时长
                uploadPartRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //设置进度回调
                uploadPartRequest.SetCosProgressCallback(delegate(long completed, long total)
                {
                    //Console.WriteLine(String.Format("{0} progress = {1} / {2} : {3:##.##}%", DateTime.Now.ToString(), completed, total, completed * 100.0 / total));
                });

                //执行请求
                UploadPartResult uploadPartResult = cosXml.UploadPart(uploadPartRequest);

                Console.WriteLine(uploadPartResult.GetResultInfo());

                string eTag = uploadPartResult.eTag;

                CompleteMultipartUploadRequest completeMultiUploadRequest = new CompleteMultipartUploadRequest(bucket, key, uploadId);
                //设置签名有效时长
                completeMultiUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //设置已上传的parts
                completeMultiUploadRequest.SetPartNumberAndETag(partNumber, eTag);

                //执行请求
                CompleteMultipartUploadResult completeMultiUploadResult = cosXml.CompleteMultiUpload(completeMultiUploadRequest);

                Console.WriteLine(completeMultiUploadResult.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }