List of usage examples for com.amazonaws.services.s3.model CopyObjectRequest setStorageClass
public void setStorageClass(StorageClass storageClass)
Sets the optional Amazon S3 storage class to use when storing the newly copied object.
From source file:nl.nn.adapterframework.filesystem.AmazonS3FileSystem.java
License:Apache License
/** * Copies a file from one Amazon S3 bucket to another one. * * @param fileName/*from w ww . j a v a2 s. c o m*/ * This is the name of the file that is desired to be copied. * * @param destinationFileName * The name of the destination file */ public String copyObject(String fileName, String destinationFileName) throws SenderException { try { bucketDoesNotExist(bucketName); //if bucket does not exists this method throws an exception fileDoesNotExist(bucketName, fileName); //if object does not exists this method throws an exception if (!s3Client.doesBucketExistV2(destinationBucketName)) bucketCreationWithObjectAction(destinationBucketName); if (!s3Client.doesObjectExist(destinationBucketName, destinationFileName)) { CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucketName, fileName, destinationBucketName, destinationFileName); if (isStorageClassEnabled()) copyObjectRequest.setStorageClass(getStorageClass()); s3Client.copyObject(copyObjectRequest); log.debug("Object with fileName [" + fileName + "] copied from bucket with bucketName [" + bucketName + "] into bucket with bucketName [" + destinationBucketName + "] and new fileName [" + destinationFileName + "]"); } else throw new SenderException(" file with given name already exists, please specify a new name"); } catch (AmazonServiceException e) { log.error("Failed to perform [copy] action on object with fileName [" + fileName + "]"); throw new SenderException("Failed to perform [copy] action on object with fileName [" + fileName + "]"); } return destinationFileName; }
From source file:org.alanwilliamson.amazon.s3.Copy.java
License:Open Source License
public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException { AmazonKey amazonKey = getAmazonKey(_session, argStruct); AmazonS3 s3Client = getAmazonS3(amazonKey); String srcbucket = getNamedStringParam(argStruct, "srcbucket", null); String srckey = getNamedStringParam(argStruct, "srckey", null); String srcaes256key = getNamedStringParam(argStruct, "srcaes256key", null); String destbucket = getNamedStringParam(argStruct, "destbucket", null); String deskey = getNamedStringParam(argStruct, "destkey", null); String destaes256key = getNamedStringParam(argStruct, "destaes256key", null); String deststorageclass = getNamedStringParam(argStruct, "deststorageclass", null); String destacl = getNamedStringParam(argStruct, "destacl", null); if (srckey != null && srckey.charAt(0) == '/') srckey = srckey.substring(1);//w w w . ja v a 2 s .c o m if (deskey != null && deskey.charAt(0) == '/') deskey = deskey.substring(1); CopyObjectRequest cor = new CopyObjectRequest(srcbucket, srckey, destbucket, deskey); if (srcaes256key != null && !srcaes256key.isEmpty()) cor.setSourceSSECustomerKey(new SSECustomerKey(srcaes256key)); if (destaes256key != null && !destaes256key.isEmpty()) cor.setDestinationSSECustomerKey(new SSECustomerKey(destaes256key)); if (deststorageclass != null && !deststorageclass.isEmpty()) cor.setStorageClass(amazonKey.getAmazonStorageClass(deststorageclass)); if (destacl != null && !destacl.isEmpty()) cor.setCannedAccessControlList(amazonKey.getAmazonCannedAcl(destacl)); try { s3Client.copyObject(cor); return cfBooleanData.TRUE; } catch (Exception e) { throwException(_session, "AmazonS3: " + e.getMessage()); return cfBooleanData.FALSE; } }
From source file:org.apache.beam.sdk.io.aws.s3.S3FileSystem.java
License:Apache License
@VisibleForTesting CopyObjectResult atomicCopy(S3ResourceId sourcePath, S3ResourceId destinationPath, ObjectMetadata sourceObjectMetadata) throws AmazonClientException { CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourcePath.getBucket(), sourcePath.getKey(), destinationPath.getBucket(), destinationPath.getKey()); copyObjectRequest.setNewObjectMetadata(sourceObjectMetadata); copyObjectRequest.setStorageClass(options.getS3StorageClass()); copyObjectRequest.setSourceSSECustomerKey(options.getSSECustomerKey()); copyObjectRequest.setDestinationSSECustomerKey(options.getSSECustomerKey()); return amazonS3.get().copyObject(copyObjectRequest); }
From source file:org.duracloud.s3storage.S3StorageProvider.java
License:Apache License
@Override public String copyContent(String sourceSpaceId, String sourceContentId, String destSpaceId, String destContentId) {/* ww w . j a va 2s .com*/ 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 {//www . ja va 2 s. c om 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.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 www . j a va 2 s . c om 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(); }