// perform operations in S3 using signed URLs (no AWS Credentials required).
// The RestS3Service provides an implementation of this interface in JetS3t.
SignedUrlHandler signedUrlHandler = new RestS3Service(null);
// Create a bucket to test reading and writing to
S3Bucket bucket = new S3Bucket(myBucketName);
// Create an object to use for testing.
S3Object object = new S3Object(bucket, "urlSigningTestObject.txt", "Hello World!");
// Determine what the time will be in 5 minutes - our signed URLs will be valid for 5 minutes only.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 5);
Date expiryDate = cal.getTime();
/*
* Generate the signed URL strings for PUT, GET, HEAD and DELETE operations, using the
* AWS Credentials in the samples.properties file.
*/
AWSCredentials awsCredentials = SamplesUtils.loadAWSCredentials();
// Create a signed HTTP PUT URL valid for 5 minutes.
String putUrl = S3Service.createSignedPutUrl(bucket.getName(), object.getKey(),
object.getMetadataMap(), awsCredentials, expiryDate, false);
// Create a signed HTTP GET URL valid for 5 minutes.
String getUrl = S3Service.createSignedGetUrl(bucket.getName(), object.getKey(),
awsCredentials, expiryDate, false);
// Create a signed HTTP HEAD URL valid for 5 minutes.
String headUrl = S3Service.createSignedHeadUrl(bucket.getName(), object.getKey(),
awsCredentials, expiryDate, false);
// Create a signed HTTP DELETE URL valid for 5 minutes.
String deleteUrl = S3Service.createSignedDeleteUrl(bucket.getName(), object.getKey(),
awsCredentials, expiryDate, false);
System.out.println("Signed PUT URL: " + putUrl);
System.out.println("Signed GET URL: " + getUrl);
System.out.println("Signed HEAD URL: " + headUrl);