本文整理汇总了C#中IAmazonS3.UploadPart方法的典型用法代码示例。如果您正苦于以下问题:C# IAmazonS3.UploadPart方法的具体用法?C# IAmazonS3.UploadPart怎么用?C# IAmazonS3.UploadPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAmazonS3
的用法示例。
在下文中一共展示了IAmazonS3.UploadPart方法的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);
}