@@ -0,0 +1,2659 @@
+// snippet-comment:%5BThese are tags for the AWS doc team's sample catalog. Do not remove.%5D%0A// snippet-sourcedescription:%5BGetObjectContentType.java demonstrates how to determine the content type of an object in an Amazon Simple Storage Service (Amazon S3) bucket.%5D%0A//snippet-keyword:%5BAWS SDK for Java v2%5D%0A//snippet-keyword:%5BCode Sample%5D%0A//snippet-service:%5BAmazon S3%5D%0A//snippet-sourcetype:%5Bfull-example%5D%0A//snippet-sourcedate:%5B01/06/2021%5D%0A//snippet-sourceauthor:%5Bscmacdon-aws%5D%0A%0A/*%0A   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A   SPDX-License-Identifier: Apache-2.0%0A*/%0A%0Apackage com.example.s3;%0A%0A// snippet-start:%5Bs3.java2.getobjectcontenttype.import%5D%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.s3.S3Client;%0Aimport software.amazon.awssdk.services.s3.model.*;%0A// snippet-end:%5Bs3.java2.getobjectcontenttype.import%5D%0A%0A/**%0A * To run this AWS code example, ensure that you have setup your development environment, including your AWS credentials.%0A *%0A * For information, see this documentation topic:%0A *%0A * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html%0A */%0A%0Apublic class GetObjectContentType %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final String USAGE = %22%5Cn%22 +%0A                %22Usage:%5Cn%22 +%0A                %22    GetObjectContentType %3CbucketName%3E %3CkeyName%3E%3E%5Cn%5Cn%22 +%0A                %22Where:%5Cn%22 +%0A                %22    bucketName - the Amazon S3 bucket name. %5Cn%5Cn%22+%0A                %22    keyName - the key name. %5Cn%5Cn%22;%0A%0A        if (args.length != 2) %7B%0A            System.out.println(USAGE);%0A            System.exit(1);%0A        %7D%0A%0A        String bucketName = args%5B0%5D;%0A        String keyName = args%5B1%5D;%0A%0A        Region region = Region.US_WEST_2;%0A        S3Client s3 = S3Client.builder()%0A                .region(region)%0A                .build();%0A%0A        getContentType(s3,bucketName,keyName);%0A        s3.close();%0A    %7D%0A%0A    // snippet-start:%5Bs3.java2.getobjectcontenttype.main%5D%0A    public static void getContentType (S3Client s3, String bucketName, String keyName) %7B%0A%0A        try %7B%0A            HeadObjectRequest objectRequest = HeadObjectRequest.builder()%0A                    .key(keyName)%0A                    .bucket(bucketName)%0A                    .build();%0A%0A            HeadObjectResponse objectHead = s3.headObject(objectRequest);%0A            String type = objectHead.contentType();%0A            System.out.println(%22The object content type is %22+type);%0A%0A        %7D catch (S3Exception e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A            System.exit(1);%0A        %7D%0A        // snippet-end:%5Bs3.java2.getobjectcontenttype.main%5D%0A    %7D%0A%7D%0A

Create GetObjectContentType.java