Aliyun.OSS.Test.TestClass.ObjectTestClass.ObjectEncodingTypeTest.ListMultipartUploadsWithHiddenCharacters C# (CSharp) Method

ListMultipartUploadsWithHiddenCharacters() public method

public ListMultipartUploadsWithHiddenCharacters ( ) : void
return void
        public void ListMultipartUploadsWithHiddenCharacters()
        {
            char[] buffer = new char[2];
            buffer[0] = Convert.ToChar(0x1c);
            buffer[1] = Convert.ToChar(0x1a);

            var newKey = _keyName + (new string(buffer)) + ".1.cd";

            try
            {
                var initRequest = new InitiateMultipartUploadRequest(_bucketName, newKey);
                var initResult = _ossClient.InitiateMultipartUpload(initRequest);
                Assert.AreEqual(newKey, initRequest.Key);

                // 设置每块为 5M
                const int partSize = 5 * 1024 * 1024;

                var fileInfo = new FileInfo(Config.MultiUploadTestFile);

                // 计算分块数目
                var partCount = OssTestUtils.CalculatePartCount(fileInfo.Length, partSize);

                // 新建一个List保存每个分块上传后的ETag和PartNumber
                var partETags = new List<PartETag>();

                //upload the file
                using (var fs = new FileStream(fileInfo.FullName, FileMode.Open))
                {
                    for (var i = 0; i < partCount; i++)
                    {
                        // 跳到每个分块的开头
                        long skipBytes = partSize * i;
                        fs.Position = skipBytes;

                        // 计算每个分块的大小
                        long size = partSize < fileInfo.Length - skipBytes ? partSize : fileInfo.Length - skipBytes;

                        // 创建UploadPartRequest,上传分块
                        var uploadPartRequest = new UploadPartRequest(_bucketName, newKey, initResult.UploadId);
                        uploadPartRequest.InputStream = fs;
                        uploadPartRequest.PartSize = size;
                        uploadPartRequest.PartNumber = (i + 1);
                        var uploadPartResult = _ossClient.UploadPart(uploadPartRequest);

                        // 将返回的PartETag保存到List中。
                        partETags.Add(uploadPartResult.PartETag);

                        var multipartListing = _ossClient.ListMultipartUploads(new ListMultipartUploadsRequest(_bucketName));
                        foreach (var upload in multipartListing.MultipartUploads)
                        {
                            Assert.AreEqual(newKey, upload.Key);
                        }
                    }
                }

                var completeRequest = new CompleteMultipartUploadRequest(_bucketName, newKey, initResult.UploadId);
                foreach (var partETag in partETags)
                {
                    completeRequest.PartETags.Add(partETag);
                }
                _ossClient.CompleteMultipartUpload(completeRequest);
            }
            finally
            {
                var multipartListing = _ossClient.ListMultipartUploads(new ListMultipartUploadsRequest(_bucketName));
                foreach (var upload in multipartListing.MultipartUploads)
                {
                    var abortRequest = new AbortMultipartUploadRequest(_bucketName, newKey, upload.UploadId);
                    _ossClient.AbortMultipartUpload(abortRequest);
                }
                _ossClient.DeleteObject(_bucketName, newKey);
            }
        }