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 destinationBucketName,
        String destinationKey) 

Source Link

Document

Constructs with basic options.

Usage

From source file:org.duracloud.s3storage.S3StorageProvider.java

License:Apache License

@Override
public String copyContent(String sourceSpaceId, String sourceContentId, String destSpaceId,
        String destContentId) {//from   www . j ava 2  s  .  c  o m
    log.debug("copyContent({}, {}, {}, {})", sourceSpaceId, sourceContentId, destSpaceId, destContentId);

    // Will throw if source bucket does not exist
    String sourceBucketName = getBucketName(sourceSpaceId);
    // Will throw if destination bucket does not exist
    String destBucketName = getBucketName(destSpaceId);

    throwIfContentNotExist(sourceBucketName, sourceContentId);

    CopyObjectRequest request = new CopyObjectRequest(sourceBucketName, sourceContentId, destBucketName,
            destContentId);
    request.setStorageClass(DEFAULT_STORAGE_CLASS);
    request.setCannedAccessControlList(CannedAccessControlList.Private);

    CopyObjectResult result = doCopyObject(request);
    return StorageProviderUtil.compareChecksum(this, sourceSpaceId, sourceContentId, result.getETag());
}

From source file:org.duracloud.s3storage.S3StorageProvider.java

License:Apache License

private void updateObjectProperties(String bucketName, String contentId, ObjectMetadata objMetadata) {
    try {//  w  w  w.ja  va  2  s .  com
        AccessControlList originalACL = s3Client.getObjectAcl(bucketName, contentId);
        CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, contentId, bucketName, contentId);
        copyRequest.setStorageClass(DEFAULT_STORAGE_CLASS);
        copyRequest.setNewObjectMetadata(objMetadata);
        s3Client.copyObject(copyRequest);
        s3Client.setObjectAcl(bucketName, contentId, originalACL);
    } catch (AmazonClientException e) {
        throwIfContentNotExist(bucketName, contentId);
        String err = "Could not update metadata for content " + contentId + " in S3 bucket " + bucketName
                + " due to error: " + e.getMessage();
        throw new StorageException(err, e, NO_RETRY);
    }
}

From source file:org.ecocean.media.S3AssetStore.java

License:Open Source License

@Override
//NOTE the aws credentials will be pulled from the current instance ("this") S3AssetStore, so must have access to both buckets
//NOTE: *** s3 might give an "invalid key" if you try to copyObject a file immediately after it was created.  ymmv.
public void copyAsset(final MediaAsset fromMA, final MediaAsset toMA) throws IOException {
    //i guess we could pass this case along to AssetStore.copyAssetAny() ??
    if ((fromMA == null) || (toMA == null) || (fromMA.getStore() == null) || (toMA.getStore() == null))
        throw new IOException("null value(s) in copyAsset()");
    if (!(fromMA.getStore() instanceof S3AssetStore) || !(toMA.getStore() instanceof S3AssetStore))
        throw new IOException("invalid AssetStore type(s)");
    if (!toMA.getStore().writable)
        throw new IOException(toMA.getStore().name + " is a read-only AssetStore");

    Object fromB = getParameter(fromMA.getParameters(), "bucket");
    Object fromK = getParameter(fromMA.getParameters(), "key");
    if ((fromB == null) || (fromK == null))
        throw new IOException("Invalid bucket and/or key value for source MA " + fromMA);
    Object toB = getParameter(toMA.getParameters(), "bucket");
    Object toK = getParameter(toMA.getParameters(), "key");
    if ((toB == null) || (toK == null))
        throw new IOException("Invalid bucket and/or key value for target MA " + toMA);
    System.out.println("S3AssetStore.copyAsset(): " + fromB.toString() + "|" + fromK.toString() + " --> "
            + toB.toString() + "|" + toK.toString());
    //getS3Client() gets aws credentials from this instance S3AssetStore
    getS3Client().copyObject(/*from w ww.  j a v a  2  s. c  om*/
            new CopyObjectRequest(fromB.toString(), fromK.toString(), toB.toString(), toK.toString()));
}

From source file:org.elasticsearch.cloud.aws.blobstore.S3BlobContainer.java

License:Apache License

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {/*from w  ww.ja va  2  s  .com*/
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
                blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }
        blobStore.client().copyObject(request);
        blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}

From source file:org.elasticsearch.repositories.s3.S3BlobContainer.java

License:Apache License

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {//from  w  ww . j a  va2s .com
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
                blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }

        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });

    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public void copyObject(String srcBucketName, String srcKey, String dstBucketName, String dstKey) {
    CopyObjectRequest request = new CopyObjectRequest(srcBucketName, srcKey, dstBucketName, dstKey);
    this.s3.copyObject(request);
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public void moveObject(String srcBucketName, String srcKey, String dstBucketName, String dstKey) {
    CopyObjectRequest request = new CopyObjectRequest(srcBucketName, srcKey, dstBucketName, dstKey);
    this.s3.copyObject(request);
    this.s3.deleteObject(srcBucketName, srcKey);
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public void renameObject(String bucketName, String oldKey, String newKey) {
    CopyObjectRequest request = new CopyObjectRequest(bucketName, oldKey, bucketName, newKey);
    this.s3.copyObject(request);
    this.s3.deleteObject(bucketName, oldKey);
}

From source file:org.fcrepo.modeshape.binary.S3BinaryStore.java

License:Apache License

@Override
protected void storeMimeType(BinaryValue binaryValue, String mimeType) throws BinaryStoreException {
    try {/*from   w w  w.  j  a v a  2 s  . c  o  m*/
        String key = binaryValue.getKey().toString();
        ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key);
        metadata.setContentType(mimeType);

        // Update the object in place
        CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, key, bucketName, key);
        copyRequest.setNewObjectMetadata(metadata);
        s3Client.copyObject(copyRequest);
    } catch (AmazonClientException e) {
        throw new BinaryStoreException(e);
    }
}

From source file:org.fcrepo.modeshape.binary.S3BinaryStore.java

License:Apache License

private void setS3ObjectUserProperty(BinaryKey binaryKey, String metadataKey, String metadataValue)
        throws BinaryStoreException {
    try {/*  w  w w  . ja  v  a2s . co  m*/
        String key = binaryKey.toString();
        ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key);
        Map<String, String> userMetadata = metadata.getUserMetadata();

        if (null != metadataValue && metadataValue.equals(userMetadata.get(metadataKey))) {
            return; // The key/value pair already exists in user metadata, skip update
        }

        userMetadata.put(metadataKey, metadataValue);
        metadata.setUserMetadata(userMetadata);

        // Update the object in place
        CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, key, bucketName, key);
        copyRequest.setNewObjectMetadata(metadata);
        s3Client.copyObject(copyRequest);
    } catch (AmazonClientException e) {
        throw new BinaryStoreException(e);
    }
}