From 6bab845fe9225a68335888c02bf45b3052bbf5bf Mon Sep 17 00:00:00 2001 From: Todd Hill Date: Mon, 23 Oct 2023 15:23:30 -0400 Subject: [PATCH] remove unused or replaced files; remove metadata.yaml --- javav2/example_code/s3/metadata.yaml | 119 ------------------ ...atePresignedUrlAndPutFileWithMetadata.java | 6 +- .../s3/GeneratePresignedUrlMetadata.java | 112 ----------------- .../s3/GeneratePresignedUrlUploadImage.java | 106 ---------------- 4 files changed, 3 insertions(+), 340 deletions(-) delete mode 100644 javav2/example_code/s3/metadata.yaml delete mode 100644 javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlMetadata.java delete mode 100644 javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlUploadImage.java diff --git a/javav2/example_code/s3/metadata.yaml b/javav2/example_code/s3/metadata.yaml deleted file mode 100644 index 2f74bf07789..00000000000 --- a/javav2/example_code/s3/metadata.yaml +++ /dev/null @@ -1,119 +0,0 @@ ---- -files: - - path: src/main/java/com/example/s3/AbortMultipartUpload.java - services: - - s3 - - path: src/main/java/com/example/s3/CopyObject.java - services: - - s3 - - path: src/main/java/com/example/s3/CreateAccessPoint.java - services: - - s3 - - path: src/main/java/com/example/s3/CreateBucket.java - services: - - s3 - - path: src/main/java/com/example/s3/CreateJob.java - services: - - s3 - - path: src/main/java/com/example/s3/GeneratePresignedUrlUploadImage - services: - - s3 - - path: src/main/java/com/example/s3/DeleteBucketPolicy.java - services: - - s3 - - path: src/main/java/com/example/s3/DeleteMultiObjects.java - services: - - s3 - - path: src/main/java/com/example/s3/DeleteObjects.java - services: - - s3 - - path: src/main/java/com/example/s3/DeleteWebsiteConfiguration.java - services: - - s3 - - path: src/main/java/com/example/s3/GeneratePresignedUrlAndUploadObject.java - services: - - s3 - - path: src/main/java/com/example/s3/GeneratePresignedUrlMetadata.java - services: - - s3 - - path: src/main/java/com/example/s3/GetAcl.java - services: - - s3 - - path: src/main/java/com/example/s3/GetBucketPolicy.java - services: - - s3 - - path: src/main/java/com/example/s3/RestoreObject.java - services: - - s3 - - path: src/main/java/com/example/s3/GetObjectContentType.java - services: - - s3 - - path: src/main/java/com/example/s3/GetObjectData.java - services: - - s3 - - path: src/main/java/com/example/s3/GetObjectPresignedUrl.java - services: - - s3 - - path: src/main/java/com/example/s3/GetObjectTags.java - services: - - s3 - - path: src/main/java/com/example/s3/GetObjectUrl.java - services: - - s3 - - path: src/main/java/com/example/s3/KMSEncryptionExample.java - services: - - s3 - - path: src/main/java/com/example/s3/LifecycleConfiguration.java - services: - - s3 - - path: src/main/java/com/example/s3/ListMultipartUploads.java - services: - - s3 - - path: src/main/java/com/example/s3/ListObjects.java - services: - - s3 - - path: src/main/java/com/example/s3/ManagingObjectTags.java - services: - - s3 - - path: src/main/java/com/example/s3/PutObject.java - services: - - s3 - - path: src/main/java/com/example/s3/PutObjectMetadata.java - services: - - s3 - - path: src/main/java/com/example/s3/PutObjectRetention.java - services: - - s3 - - path: src/main/java/com/example/s3/S3AsyncOps.java - services: - - s3 - - path: src/main/java/com/example/s3/S3AsyncStreamOps.java - services: - - s3 - - path: src/main/java/com/example/s3/S3BucketDeletion.java - services: - - s3 - - path: src/main/java/com/example/s3/S3BucketOps.java - services: - - s3 - - path: src/main/java/com/example/s3/S3Cors.java - services: - - s3 - - path: src/main/java/com/example/s3/S3Log.java - services: - - s3 - - path: src/main/java/com/example/s3/S3ObjectOperations.java - services: - - s3 - - path: src/main/java/com/example/s3/SetAcl.java - services: - - s3 - - path: src/main/java/com/example/s3/SetBucketPolicy.java - services: - - s3 - - path: src/main/java/com/example/s3/SetWebsiteConfiguration.java - services: - - s3 - - path: src/test/java/AmazonS3Test.java - services: - - s3 diff --git a/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlAndPutFileWithMetadata.java b/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlAndPutFileWithMetadata.java index f394ea69eaa..dd084ae21b5 100644 --- a/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlAndPutFileWithMetadata.java +++ b/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlAndPutFileWithMetadata.java @@ -51,14 +51,15 @@ public static void main(String[] args) { String keyName = "k-" + UUID.randomUUID(); String resourcePath = "multipartUploadFiles/s3-userguide.pdf"; String contentType = "application/pdf"; + // Uncomment the following two lines and comment out the previous two lines to use an image file instead of a PDF file. + //String resourcePath = "image.png"; + //String contentType = "image/png"; Map metadata = Map.of( "author", "Mary Doe", "version", "1.0.0.0" ); - //String resourcePath = "image.png"; - //String contentType = "image/png"; PresignUrlUtils.createBucket(bucketName, s3Client); GeneratePresignedUrlAndPutFileWithMetadata presign = new GeneratePresignedUrlAndPutFileWithMetadata(); @@ -73,7 +74,6 @@ public static void main(String[] args) { } // snippet-start:[presigned.java2.generatepresignedurlandputfilewithmetadata.main] - /** * Create a presigned URL for uploading with a PUT request. * @param bucketName - The name of the bucket. diff --git a/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlMetadata.java b/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlMetadata.java deleted file mode 100644 index 409d9518fdd..00000000000 --- a/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlMetadata.java +++ /dev/null @@ -1,112 +0,0 @@ -// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] -// snippet-sourcedescription:[GeneratePresignedUrlAndUploadObject.java demonstrates how to use the S3Presigner client to create a presigned URL and upload an object that contains metadata to an Amazon Simple Storage Service (Amazon S3) bucket.] -//snippet-keyword:[AWS SDK for Java v2] -//snippet-service:[Amazon S3] - -/* - Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - SPDX-License-Identifier: Apache-2.0 -*/ -package com.example.s3; - -// snippet-start:[presigned.java2.generatepresignedurl.metadata.import] -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; -import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.s3.model.PutObjectRequest; -import software.amazon.awssdk.services.s3.model.S3Exception; -import software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest; -import software.amazon.awssdk.services.s3.presigner.S3Presigner; -import software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest; -// snippet-end:[presigned.java2.generatepresignedurl.metadata.import] - -/** - * Before running this Java V2 code example, set up your development environment, including your credentials. - * - * For more information, see the following documentation topic: - * - * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html - */ - -public class GeneratePresignedUrlMetadata { - - public static void main(String[] args) { - - final String usage = "\n" + - "Usage:\n" + - " GeneratePresignedUrlAndUploadObject \n\n" + - "Where:\n" + - " bucketName - The name of the Amazon S3 bucket. \n\n" + - " keyName - A key name that represents a text file. \n" ; - - if (args.length != 2) { - System.out.println(usage); - System.exit(1); - } - - String bucketName = args[0]; - String keyName = args[1]; - ProfileCredentialsProvider credentialsProvider = ProfileCredentialsProvider.create(); - Region region = Region.US_EAST_1; - S3Presigner presigner = S3Presigner.builder() - .region(region) - .credentialsProvider(credentialsProvider) - .build(); - - signBucket(presigner, bucketName, keyName); - presigner.close(); - } - - // snippet-start:[presigned.java2.generatepresignedurl.metadata.main] - public static void signBucket(S3Presigner presigner, String bucketName, String keyName) { - - try { - Map metadata = new HashMap<>(); - metadata.put("author","Mary Doe"); - metadata.put("version","1.0.0.0"); - - PutObjectRequest objectRequest = PutObjectRequest.builder() - .bucket(bucketName) - .key(keyName) - .contentType("text/plain") - .metadata(metadata) - .build(); - - PutObjectPresignRequest presignRequest = PutObjectPresignRequest.builder() - .signatureDuration(Duration.ofMinutes(10)) - .putObjectRequest(objectRequest) - .build(); - - PresignedPutObjectRequest presignedRequest = presigner.presignPutObject(presignRequest); - System.out.println("Presigned URL to upload a file to: " + presignedRequest.url()); - System.out.println("Which HTTP method needs to be used when uploading a file: " + presignedRequest.httpRequest().method()); - - // Upload content to the Amazon S3 bucket by using this URL. - URL url = presignedRequest.url(); - - // Create the connection and use it to upload the new object. - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Type","text/plain"); - connection.setRequestProperty("x-amz-meta-author","Mary Doe"); - connection.setRequestProperty("x-amz-meta-version","1.0.0.0"); - connection.setRequestMethod("PUT"); - OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); - out.write("This text was uploaded as an object by using a presigned URL."); - out.close(); - - connection.getResponseCode(); - System.out.println("HTTP response code is " + connection.getResponseCode()); - - } catch (S3Exception | IOException e) { - e.getStackTrace(); - } - } - // snippet-end:[presigned.java2.generatepresignedurl.metadata.main] -} diff --git a/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlUploadImage.java b/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlUploadImage.java deleted file mode 100644 index c6bb89beb19..00000000000 --- a/javav2/example_code/s3/src/main/java/com/example/s3/GeneratePresignedUrlUploadImage.java +++ /dev/null @@ -1,106 +0,0 @@ -// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] -// snippet-sourcedescription:[GeneratePresignedUrlUploadImage.java demonstrates how to use the S3Presigner client to create a presigned URL and upload a PNG image file.] -// snippet-keyword:[AWS SDK for Java v2] -// snippet-service:[Amazon S3] - -/* - Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - SPDX-License-Identifier: Apache-2.0 -*/ -package com.example.s3; - -// snippet-start:[presigned.java2.generatepresignedurlimage.import] -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.time.Duration; -import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.s3.model.PutObjectRequest; -import software.amazon.awssdk.services.s3.model.S3Exception; -import software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest; -import software.amazon.awssdk.services.s3.presigner.S3Presigner; -import software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest; -// snippet-end:[presigned.java2.generatepresignedurlimage.import] - -/** - * Before running this Java V2 code example, set up your development environment, including your credentials. - * - * For more information, see the following documentation topic: - * - * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html - */ - -public class GeneratePresignedUrlUploadImage { - - public static void main(String[] args) throws IOException { - - final String usage = "\n" + - "Usage:\n" + - " \n\n" + - "Where:\n" + - " bucketName - The name of the Amazon S3 bucket. \n\n" + - " keyName - A key name that represents a text file. \n" + - " imageLocation - The location of a PNG file (C:/AWS/Bo.png). \n" ; - - if (args.length != 3) { - System.out.println(usage); - System.exit(1); - } - - String bucketName = args[0]; - String keyName = args[1]; - String imageLocation = args[2] ; - byte[] pic = Files.readAllBytes(Paths.get(imageLocation)); - ProfileCredentialsProvider credentialsProvider = ProfileCredentialsProvider.create(); - Region region = Region.US_EAST_1; - S3Presigner presigner = S3Presigner.builder() - .region(region) - .credentialsProvider(credentialsProvider) - .build(); - - signBucket(presigner, bucketName, keyName, pic); - presigner.close(); - } - - // snippet-start:[presigned.java2.generatepresignedurlimage.main] - public static void signBucket(S3Presigner presigner, String bucketName, String keyName, byte[] pic) { - - try { - PutObjectRequest objectRequest = PutObjectRequest.builder() - .bucket(bucketName) - .key(keyName) - .contentType("image/png") - .build(); - - PutObjectPresignRequest presignRequest = PutObjectPresignRequest.builder() - .signatureDuration(Duration.ofMinutes(10)) - .putObjectRequest(objectRequest) - .build(); - - PresignedPutObjectRequest presignedRequest = presigner.presignPutObject(presignRequest); - String myURL = presignedRequest.url().toString(); - System.out.println("Presigned URL to upload a file to: " +myURL); - System.out.println("Which HTTP method needs to be used when uploading a file: " + presignedRequest.httpRequest().method()); - - // Upload content to the Amazon S3 bucket by using this URL. - URL url = presignedRequest.url(); - - // Create the connection and use it to upload the new object by using the presigned URL. - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Type","image/png"); - connection.setRequestMethod("PUT"); - connection.getOutputStream().write(pic); - connection.getResponseCode(); - System.out.println("HTTP response code is " + connection.getResponseCode()); - - } catch (S3Exception | IOException e) { - e.getStackTrace(); - } - } - // snippet-end:[presigned.java2.generatepresignedurlimage.main] -} -