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

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

Introduction

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

Prototype

public CopyObjectRequest withNewObjectMetadata(ObjectMetadata newObjectMetadata) 

Source Link

Document

Sets the object metadata to use for the new, copied object and returns this object, enabling additional method calls to be chained together.

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 ww w .j a  v a2  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;
    }
}

From source file:io.druid.storage.s3.S3ServerSideEncryption.java

License:Apache License

@Override
public CopyObjectRequest decorate(CopyObjectRequest request) {
    final ObjectMetadata objectMetadata = request.getNewObjectMetadata() == null ? new ObjectMetadata()
            : request.getNewObjectMetadata().clone();
    objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    return request.withNewObjectMetadata(objectMetadata);
}