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

Track Multipart Upload Progress

The high-level Java multipart upload API provides a listen interface, ProgressListener, to track progress when uploading an object to Amazon S3. Progress events periodically notify the listener that bytes have been transferred.

The following example demonstrates how to subscribe to a ProgressEvent event and write a handler:

import; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.event.ProgressEvent; import com.amazonaws.event.ProgressListener; import; import; import; import; import; import; public class HighLevelTrackMultipartUpload { public static void main(String[] args) throws Exception { String clientRegion = "*** Client region ***"; String bucketName = "*** Bucket name ***"; String keyName = "*** Object key ***"; String filePath = "*** Path to file to upload ***"; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(clientRegion) .withCredentials(new ProfileCredentialsProvider()) .build(); TransferManager tm = TransferManagerBuilder.standard() .withS3Client(s3Client) .build(); PutObjectRequest request = new PutObjectRequest(bucketName, keyName, new File(filePath)); // To receive notifications when bytes are transferred, add a // ProgressListener to your request. request.setGeneralProgressListener(new ProgressListener() { public void progressChanged(ProgressEvent progressEvent) { System.out.println("Transferred bytes: " + progressEvent.getBytesTransferred()); } }); // TransferManager processes all transfers asynchronously, // so this call returns immediately. Upload upload = tm.upload(request); // Optionally, you can wait for the upload to finish before continuing. upload.waitForCompletion(); } catch(AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch(SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }