6.2 SecureAmazonS3Client s3 app code snippets

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:

  • AmazonS3Client --> SecureAmazonS3Client

6.2.1 Downloading Objects using Bayun's SecureAmazonS3Client

SecureAmazonS3Client s3 = new SecureAmazonS3Client(credentialsProvider, appContext);       
S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
InputStream objectData = object.getObjectContent();
// Process the objectData stream.
objectData.close();
GetObjectRequest rangeObjectRequest = new GetObjectRequest(bucketName, key);
rangeObjectRequest.setRange(0, 10); // retrieve 1st 11 bytes.
S3Object objectPortion = secureAWSS3Client.getObject(rangeObjectRequest);

InputStream objectData = objectPortion.getObjectContent();
// Process the objectData stream.
objectData.close();va
GetObjectRequest request = new GetObjectRequest(bucketName, key);

ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
responseHeaders.setCacheControl("No-cache");
responseHeaders.setContentDisposition("attachment; filename=testing.txt");

// Add the ResponseHeaderOverides to the request.
request.setResponseHeaders(responseHeaders);

6.2.2 Uploading Objects using Bayun's SecureAmazonS3Client

SecureAmazonS3Client s3 = new SecureAmazonS3Client(credentialsProvider, appContext);   
s3.putObject(new PutObjectRequest(bucketName, keyName, file));

Last updated