5.2 Transferring Data using Bayun's SecureTransferUtility

Now in order to use Bayun’s S3Wrapper instead of the standard AWS S3 SDK classes, these code snippets above change to using “Secure” versions of the corresponding classes, as below:

  • As you can see from the code snippets below, in general it should be possible to simply query-replace the following type-names appropriately to their secure versions, and in most situations that should be sufficient.

    • AmazonS3Client --> SecureAmazonS3Client

    • TransferUtility --> SecureTransferUtility

  • Add the following to the import statements:

import com.bayun.S3wrapper.SecureAmazonS3Client;
import com.bayun.S3wrapper.SecureTransferUtility;

5.2.1 Initialize the SecureTransferUtility

SecureAmazonS3Client s3 = new SecureAmazonS3Client(credentialsProvider, appContext);
SecureTransferUtility transferUtility = new SecureTransferUtility(s3, appContext);

5.2.2 Upload a File to Amazon S3 using SecureTransferUtility

TransferObserver transferObserver = secureTransferUtility.secureUpload(
  MY_BUCKET,     /* The bucket to upload to */
  OBJECT_KEY,    /* The key for the uploaded object */
  MY_FILE,       /* The file where the data to upload exists */
  null           /* The transferListener to track progress */
);

5.2.3 Download a File from Amazon S3 using SecureTransferUtility

TransferObserver transferObserver = secureTransferUtility.secureDownload(
  MY_BUCKET,     /* The bucket to download from */
  OBJECT_KEY,    /* The key for the object to download */
  MY_FILE,       /* The file to download the object to */
  null           /* The transferListener to track progress */
);

5.2.4 Tracking S3 Transfer Progress using TransferObserver

TransferObserver transferObserver = secureTransferUtility.secureDownload(
  MY_BUCKET,     /* The bucket to download from */
  OBJECT_KEY,    /* The key for the object to download */
  MY_FILE,       /* The file to download the object to */
  null           /* The transferListener to track progress */
);

By doing the above, all data written to S3 is automatically locked before upload and unlocked after download in such a manner that nobody other than the customer (and especially the developer) has access to any of the encryption keys or the data itself.

Last updated