List of usage examples for com.amazonaws SDKGlobalConfiguration ENABLE_S3_SIGV4_SYSTEM_PROPERTY
String ENABLE_S3_SIGV4_SYSTEM_PROPERTY
To view the source code for com.amazonaws SDKGlobalConfiguration ENABLE_S3_SIGV4_SYSTEM_PROPERTY.
Click Source Link
From source file:com.kirana.utils.GeneratePresignedUrlAndUploadObject.java
public static void main(String[] args) throws IOException { System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "true"); System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "AKIAJ666LALJZHA6THGQ"); System.setProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "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"); // AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider("kirana")); ProfilesConfigFile profile = new ProfilesConfigFile("AwsCredentials.properties"); AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider()); s3client.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1)); try {//from www . jav a2 s .co m System.out.println("Generating pre-signed URL."); java.util.Date expiration = new java.util.Date(); long milliSeconds = expiration.getTime(); milliSeconds += 1000 * 60 * 60; // Add 1 hour. expiration.setTime(milliSeconds); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey); generatePresignedUrlRequest.setMethod(HttpMethod.PUT); generatePresignedUrlRequest.setExpiration(expiration); // s3client.putObject(bucketName, objectKey, null); URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest); UploadObject(url); System.out.println("Pre-Signed URL = " + url.toString()); } catch (AmazonServiceException exception) { System.out.println("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason."); System.out.println("Error Message: " + exception.getMessage()); System.out.println("HTTP Code: " + exception.getStatusCode()); System.out.println("AWS Error Code:" + exception.getErrorCode()); System.out.println("Error Type: " + exception.getErrorType()); System.out.println("Request ID: " + exception.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, " + "which means the client encountered " + "an internal error while trying to communicate" + " with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }