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

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

Introduction

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

Prototype

public CopyObjectRequest(String sourceBucketName, String sourceKey, String sourceVersionId,
        String destinationBucketName, String destinationKey) 

Source Link

Document

Constructs a new CopyObjectRequest with basic options, providing an S3 version ID identifying the specific version of the source object to copy.

Usage

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public CopyObjectResponseType copyObject(CopyObjectType request) throws S3Exception {
    CopyObjectResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    String sourceBucket = request.getSourceBucket();
    String sourceKey = request.getSourceObject();
    String sourceVersionId = request.getSourceVersionId();
    String destinationBucket = request.getDestinationBucket();
    String destinationKey = request.getDestinationObject();
    String copyIfMatch = request.getCopySourceIfMatch();
    String copyIfNoneMatch = request.getCopySourceIfNoneMatch();
    Date copyIfUnmodifiedSince = request.getCopySourceIfUnmodifiedSince();
    Date copyIfModifiedSince = request.getCopySourceIfModifiedSince();
    try {/*from w  ww.  j  a va  2  s.co m*/
        CopyObjectRequest copyRequest = new CopyObjectRequest(sourceBucket, sourceKey, sourceVersionId,
                destinationBucket, destinationKey);
        copyRequest.setModifiedSinceConstraint(copyIfModifiedSince);
        copyRequest.setUnmodifiedSinceConstraint(copyIfUnmodifiedSince);
        if (copyIfMatch != null) {
            List<String> copyIfMatchConstraint = new ArrayList<String>();
            copyIfMatchConstraint.add(copyIfMatch);
            copyRequest.setMatchingETagConstraints(copyIfMatchConstraint);
        }
        if (copyIfNoneMatch != null) {
            List<String> copyIfNoneMatchConstraint = new ArrayList<String>();
            copyIfNoneMatchConstraint.add(copyIfNoneMatch);
            copyRequest.setNonmatchingETagConstraints(copyIfNoneMatchConstraint);
        }
        //TODO: Need to set canned ACL if specified
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        CopyObjectResult result = s3Client.copyObject(copyRequest);
        reply.setEtag(result.getETag());
        reply.setLastModified(DateFormatter.dateToListingFormattedString(result.getLastModifiedDate()));
        String destinationVersionId = result.getVersionId();
        if (destinationVersionId != null) {
            reply.setCopySourceVersionId(sourceVersionId);
            reply.setVersionId(destinationVersionId);
        }
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
    return reply;

}

From source file:org.mule.module.s3.simpleapi.SimpleAmazonS3AmazonDevKitImpl.java

License:Open Source License

public String copyObject(@NotNull S3ObjectId source, @NotNull S3ObjectId destination,
        @NotNull ConditionalConstraints conditionalConstraints, CannedAccessControlList acl,
        StorageClass storageClass, Map<String, String> userMetadata, String encryption) {
    Validate.notNull(source);/*from   w w  w  .j  a  v a  2 s .  c o m*/
    Validate.notNull(destination);
    Validate.notNull(conditionalConstraints);
    CopyObjectRequest request = new CopyObjectRequest(source.getBucketName(), source.getKey(),
            source.getVersionId(), destination.getBucketName(), destination.getKey());
    request.setCannedAccessControlList(acl);
    if (storageClass != null) {
        request.setStorageClass(storageClass);
    }

    if (encryption != null) {
        request.setNewObjectMetadata(new ObjectMetadata());
        request.getNewObjectMetadata().setServerSideEncryption(encryption);
        if (userMetadata != null) {
            request.getNewObjectMetadata().setUserMetadata(userMetadata);
        }
    } else if (userMetadata != null) {
        request.setNewObjectMetadata(new ObjectMetadata());
        request.getNewObjectMetadata().setUserMetadata(userMetadata);
    }

    conditionalConstraints.populate(request);
    return s3.copyObject(request).getVersionId();
}