Example usage for com.amazonaws.services.s3.model CopyObjectRequest withAccessControlList

List of usage examples for com.amazonaws.services.s3.model CopyObjectRequest withAccessControlList

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model CopyObjectRequest withAccessControlList.

Prototype

public CopyObjectRequest withAccessControlList(AccessControlList accessControlList) 

Source Link

Document

Sets the optional access control list for the new object.

Usage

From source file:ca.pgon.amazons3masscontenttype.App.java

License:Apache License

private static void process(ObjectListing objectListing) {
    for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        // Show the key
        String key = objectSummary.getKey();
        System.out.println(key);//from  w w w .j av a 2  s.co m

        // Get the metadata and check the content type
        ObjectMetadata objectMetadata = amazonS3Client.getObjectMetadata(bucketName, key);
        System.out.println("\tCurrent content type: " + objectMetadata.getContentType());
        if (!contentType.equals(objectMetadata.getContentType())) {
            System.out.println("\tChanging content type for : " + contentType);
            objectMetadata.setContentType(contentType);

            // Get the current ACL
            AccessControlList accessControlList = amazonS3Client.getObjectAcl(bucketName, key);

            // Modify the file
            CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucketName, key, bucketName, key);
            copyObjectRequest.withNewObjectMetadata(objectMetadata);
            copyObjectRequest.withAccessControlList(accessControlList);
            amazonS3Client.copyObject(copyObjectRequest);
        }
        ++count;
    }
}