public static void UploadWithUploadId(CosXml cosXml, string bucket, string key, string srcPath, long offset, long sendContentLength)
        {
            TransferConfig transferConfig = new TransferConfig();

            transferManager = new TransferManager(cosXml, new TransferConfig());
            COSXML.Model.Object.InitMultipartUploadRequest initMultipartUploadRequest = new COSXML.Model.Object.InitMultipartUploadRequest(bucket, key);
            COSXML.Model.Object.InitMultipartUploadResult  initMultipartUploadResult  = cosXml.InitMultipartUpload(initMultipartUploadRequest);
            string upLoadId = initMultipartUploadResult.initMultipartUpload.uploadId;

            //string content = "this is partNumber 1";
            byte[] data = new byte[transferConfig.SliceSizeForUpload];
            COSXML.Model.Object.UploadPartRequest uploadPartRequest = new COSXML.Model.Object.UploadPartRequest(bucket, key, 1, upLoadId, data);
            COSXML.Model.Object.UploadPartResult  uploadPartResult  = cosXml.UploadPart(uploadPartRequest);
            string eTag = uploadPartResult.eTag;

            COSXMLUploadTask uploadTask = new COSXMLUploadTask(bucket, null, key)
            {
                progressCallback = delegate(long completed, long total)
                {
                    Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total));
                },
                successCallback = delegate(CosResult cosResult)
                {
                    COSXML.Transfer.COSXMLUploadTask.UploadTaskResult result = cosResult as COSXML.Transfer.COSXMLUploadTask.UploadTaskResult;
                    QLog.D("XIAO", result.GetResultInfo());
                    Console.WriteLine(result.GetResultInfo());
                    Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
                },
                failCallback = 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));
                }
            };

            uploadTask.SetSrcPath(srcPath, offset, sendContentLength);
            uploadTask.SetUploadId(upLoadId);
            transferManager.Upload(uploadTask);
        }
Exemplo n.º 2
0
 /// 上传一个分片
 private void UploadPart(int partNumber, long partSize, string srcPath)
 {
     try
     {
         UploadPartRequest request = new UploadPartRequest(bucket, key, partNumber,
                                                           this.uploadId, srcPath, partSize * (partNumber - 1), partSize);
         //执行请求
         UploadPartResult result = cosXml.UploadPart(request);
         //请求成功
         //获取返回分块的eTag,用于后续CompleteMultiUploads
         partNumberAndETags.Add(partNumber, result.eTag);
         //Console.WriteLine(result.GetResultInfo());
     }
     catch (COSXML.CosException.CosClientException clientEx)
     {
         //请求失败
         Console.WriteLine("CosClientException: " + clientEx);
         InfoLog.InfoPrintf($"Cos: CosClientException: {clientEx}", InfoLog.InfoClass.系统错误信息);
     }
 }
Exemplo n.º 3
0
        /// 上传一个分片
        public void UploadPart()
        {
            //.cssg-snippet-body-start:[upload-part]
            try
            {
                string            bucket     = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
                string            key        = "exampleobject";            //对象键
                string            uploadId   = "exampleUploadId";          //初始化分块上传返回的uploadId
                int               partNumber = 1;                          //分块编号,必须从1开始递增
                string            srcPath    = @"temp-source-file";        //本地文件绝对路径
                UploadPartRequest request    = new UploadPartRequest(bucket, key, partNumber,
                                                                     uploadId, srcPath);
                //设置进度回调
                request.SetCosProgressCallback(delegate(long completed, long total)
                {
                    Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
                });
                //执行请求
                UploadPartResult result = cosXml.UploadPart(request);
                //请求成功
                //获取返回分块的eTag,用于后续CompleteMultiUploads
                this.eTag = result.eTag;
                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
        }