当前位置: 首页>>代码示例>>C#>>正文


C# IAmazonS3.CompleteMultipartUpload方法代码示例

本文整理汇总了C#中IAmazonS3.CompleteMultipartUpload方法的典型用法代码示例。如果您正苦于以下问题:C# IAmazonS3.CompleteMultipartUpload方法的具体用法?C# IAmazonS3.CompleteMultipartUpload怎么用?C# IAmazonS3.CompleteMultipartUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAmazonS3的用法示例。


在下文中一共展示了IAmazonS3.CompleteMultipartUpload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadUsingMultiPartAPI

        /// <summary>
        /// Sample code to contrast uploading a file using Amazon S3's Multi-Part Upload API
        /// </summary>
        /// <param name="s3Client"></param>
        /// <param name="bucketName"></param>
        /// <param name="fileName"></param>
        static void UploadUsingMultiPartAPI(IAmazonS3 s3Client, string bucketName, string fileName)
        {
            const string objectKey = "multipart/myobject";

            // tell S3 we're going to upload an object in multiple parts and receive an upload ID
            // in return
            var initializeUploadRequest = new InitiateMultipartUploadRequest
            {
                BucketName = bucketName,
                Key = objectKey
            };
            var initializeUploadResponse = s3Client.InitiateMultipartUpload(initializeUploadRequest);

            // this ID must accompany all parts and the final 'completed' call
            var uploadID = initializeUploadResponse.UploadId;

            // Send the file (synchronously) using 4*5MB parts - note we pass the upload id
            // with each call. For each part we need to log the returned etag value to pass
            // to the completion call
            var partETags = new List<PartETag>();
            var partSize = 5 * ONE_MEG; // this is the minimum part size allowed

            for (var partNumber = 0; partNumber < 4; partNumber++)
            {
                // part numbers must be between 1 and 1000
                var logicalPartNumber = partNumber + 1;
                var uploadPartRequest = new UploadPartRequest
                {
                    BucketName = bucketName,
                    Key = objectKey,
                    UploadId = uploadID,
                    PartNumber = logicalPartNumber,
                    PartSize = partSize,
                    FilePosition = partNumber * partSize,
                    FilePath = fileName
                };

                var partUploadResponse = s3Client.UploadPart(uploadPartRequest);
                partETags.Add(new PartETag { PartNumber = logicalPartNumber, ETag = partUploadResponse.ETag });
            }

            var completeUploadRequest = new CompleteMultipartUploadRequest
            {
                BucketName = bucketName,
                Key = objectKey,
                UploadId = uploadID,
                PartETags = partETags
            };

            s3Client.CompleteMultipartUpload(completeUploadRequest);
        }
开发者ID:jamisliao,项目名称:aws-sdk-net-samples,代码行数:57,代码来源:Program.cs


注:本文中的IAmazonS3.CompleteMultipartUpload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。