use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class PutObjectMetadata method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <bucketName> <objectKey> <objectPath> \n\n" + "Where:\n" + " bucketName - the Amazon S3 bucket to upload an object into.\n" + " objectKey - the object to upload (for example, book.pdf).\n" + " objectPath - the path where the file is located (for example, C:/AWS/book2.pdf). \n\n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
String objectKey = args[1];
String objectPath = args[2];
System.out.println("Putting object " + objectKey + " into bucket " + bucketName);
System.out.println(" in bucket: " + bucketName);
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder().region(region).build();
String result = putS3Object(s3, bucketName, objectKey, objectPath);
System.out.println("Tag information: " + result);
s3.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class PutObjectMetadata method putS3Object.
// snippet-start:[s3.java2.s3_object_upload.metadata.main]
public static String putS3Object(S3Client s3, String bucketName, String objectKey, String objectPath) {
try {
// Define the metadata
Map<String, String> metadata = new HashMap<>();
metadata.put("author", "Mary Doe");
metadata.put("version", "1.0.0.0");
PutObjectRequest putOb = PutObjectRequest.builder().bucket(bucketName).key(objectKey).metadata(metadata).build();
PutObjectResponse response = s3.putObject(putOb, RequestBody.fromBytes(getObjectFile(objectPath)));
return response.eTag();
} catch (S3Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class RestoreObject method restoreS3Object.
// snippet-start:[s3.java2.restore_object.main]
public static void restoreS3Object(S3Client s3, String bucketName, String keyName, String expectedBucketOwner) {
try {
RestoreRequest restoreRequest = RestoreRequest.builder().days(10).glacierJobParameters(GlacierJobParameters.builder().tier(Tier.STANDARD).build()).build();
RestoreObjectRequest objectRequest = RestoreObjectRequest.builder().expectedBucketOwner(expectedBucketOwner).bucket(bucketName).key(keyName).restoreRequest(restoreRequest).build();
s3.restoreObject(objectRequest);
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
s3.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class RestoreObject method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <bucketName> <keyName> <expectedBucketOwner>\n\n" + "Where:\n" + " bucketName - the Amazon S3 bucket name. \n\n" + " keyName - the key name of an object with a Storage class value of Glacier. \n\n" + " expectedBucketOwner - the account that owns the bucket (you can obtain this value from the AWS Management Console). \n\n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
String keyName = args[1];
String expectedBucketOwner = args[2];
Region region = Region.US_WEST_2;
S3Client s3 = S3Client.builder().region(region).build();
restoreS3Object(s3, bucketName, keyName, expectedBucketOwner);
s3.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class S3BucketOps method createBucket.
// snippet-start:[s3.java2.s3_bucket_ops.create_bucket]
// Create a bucket by using a S3Waiter object
public static void createBucket(S3Client s3Client, String bucketName) {
try {
S3Waiter s3Waiter = s3Client.waiter();
CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
s3Client.createBucket(bucketRequest);
HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
// Wait until the bucket is created and print out the response
WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
waiterResponse.matched().response().ifPresent(System.out::println);
System.out.println(bucketName + " is ready");
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations