Menu
Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)

Track Multipart Upload Progress

The high-level multipart upload API provides an event, TransferUtilityUploadRequest.UploadProgressEvent, to track the upload progress when uploading data using the TransferUtility class.

The event occurs periodically and returns multipart upload progress information such as the total number of bytes to transfer, and the number of bytes transferred at the time event occurred.

The following C# code sample demonstrates how you can subscribe to the UploadProgressEvent event and write a handler.

Copy
TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1)); // Use TransferUtilityUploadRequest to configure options. // In this example we subscribe to an event. TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest { BucketName = existingBucketName, FilePath = filePath, Key = keyName }; uploadRequest.UploadProgressEvent += new EventHandler<UploadProgressArgs> (uploadRequest_UploadPartProgressEvent); fileTransferUtility.Upload(uploadRequest); static void uploadRequest_UploadPartProgressEvent(object sender, UploadProgressArgs e) { // Process event. Console.WriteLine("{0}/{1}", e.TransferredBytes, e.TotalBytes); }

Example

The following C# code example uploads a file to an Amazon S3 bucket and tracks the progress by subscribing to the TransferUtilityUploadRequest.UploadProgressEvent event. For instructions on how to create and test a working sample, see Running the Amazon S3 .NET Code Examples.

Copy
using System; using System.Collections.Specialized; using System.Configuration; using Amazon.S3; using Amazon.S3.Transfer; namespace s3.amazon.com.docsamples { class TrackMPUUsingHighLevelAPI { static string existingBucketName = "*** Provide bucket name ***"; static string keyName = "*** Provide key name ***"; static string filePath = "*** Provide file to upload ***"; static void Main(string[] args) { try { TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1)); // Use TransferUtilityUploadRequest to configure options. // In this example we subscribe to an event. TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest { BucketName = existingBucketName, FilePath = filePath, Key = keyName }; uploadRequest.UploadProgressEvent += new EventHandler<UploadProgressArgs> (uploadRequest_UploadPartProgressEvent); fileTransferUtility.Upload(uploadRequest); Console.WriteLine("Upload completed"); } catch (AmazonS3Exception e) { Console.WriteLine(e.Message, e.InnerException); } } static void uploadRequest_UploadPartProgressEvent( object sender, UploadProgressArgs e) { // Process event. Console.WriteLine("{0}/{1}", e.TransferredBytes, e.TotalBytes); } } }