public CopyObjectResult copyObject(CopyObjectRequest request) { return amazonS3.copyObject(serverSideEncryption.decorate(request)); }
public static void main(String[] args) { final String USAGE = "\n" + "To run this example, supply the name (key) of an S3 object, the bucket name\n" + "that it's contained within, and the bucket to copy it to.\n" + "\n" + "Ex: CopyObject <objectname> <frombucket> <tobucket>\n"; if (args.length < 3) { System.out.println(USAGE); System.exit(1); } String object_key = args[0]; String from_bucket = args[1]; String to_bucket = args[2]; System.out.format("Copying object %s from bucket %s to %s\n", object_key, from_bucket, to_bucket); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try { s3.copyObject(from_bucket, object_key, to_bucket, object_key); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } System.out.println("Done!"); } }
s3.copyObject(getBucketName(uri), keyFromPath(src), getBucketName(uri), keyFromPath(dst)); delete(src, true);
/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }
@Override public Void call() { s3.copyObject(cReq); return null; } }, OPERATION_UPDATE_METADATA);
/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }
public CopyObjectResult copyObject(CopyObjectRequest request) { return amazonS3.copyObject(serverSideEncryption.decorate(request)); }
@Override public void copyFile(final String sourceKey, final String targetKey) { amazonS3.copyObject(this.awsS3Bucket.getName(), sourceKey, this.awsS3Bucket.getName(), targetKey); logger.info("Copied [{}] to [{}]", sourceKey, targetKey); } }
@Override public void backupAsAux(String auxItemTag) throws IOException { String destinationKey = getDestinationKey(auxItemTag); try { s3.copyObject(new CopyObjectRequest(bucketName, key, bucketName, destinationKey)); } catch (AmazonClientException ase) { logger.warning("Caught an AmazonClientException in S3AccessIO.backupAsAux: " + ase.getMessage()); throw new IOException("S3AccessIO: Unable to backup original auxiliary object"); } }
@Override public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().copyObject(sourceBucketName, sourceKey, destinationBucketName, destinationKey)); }
@Override public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().copyObject(copyObjectRequest)); }
@Override public void revertBackupAsAux(String auxItemTag) throws IOException { String destinationKey = getDestinationKey(auxItemTag); try { s3.copyObject(new CopyObjectRequest(bucketName, destinationKey, bucketName, key)); deleteAuxObject(auxItemTag); } catch (AmazonClientException ase) { logger.warning("Caught an AmazonServiceException in S3AccessIO.backupAsAux: " + ase.getMessage()); throw new IOException("S3AccessIO: Unable to revert backup auxiliary object"); } }
@Override public void renameFile(String from, String to, String pp) throws IOException { while (from.startsWith(File.separator)) from = from.substring(1); while (to.startsWith(File.separator)) to = to.substring(1); String fn = EncyptUtils.encString(from, Main.chunkStoreEncryptionEnabled); String tn = EncyptUtils.encString(to, Main.chunkStoreEncryptionEnabled); try { CopyObjectRequest req = new CopyObjectRequest(this.name, pp + "/" + fn, this.name, pp + "/" + tn); s3Service.copyObject(req); req = new CopyObjectRequest(this.name, pp + "/" + fn + mdExt, this.name, pp + "/" + tn + mdExt); s3Service.copyObject(req); s3Service.deleteObject(this.name, pp + "/" + fn); if (this.simpleMD) s3Service.deleteObject(this.name, pp + "/" + fn + mdExt); } catch (Exception e1) { throw new IOException(e1); } }
@Override public FileData copy(String srcName, FileData destData) throws IOException { try { s3.copyObject(bucketName, srcName, bucketName, destData.getName()); onModified(); return check(destData.getName()); } catch (SdkClientException e) { throw new IOException(e); } }
@Override public void rename(String pathFrom, String pathTo) throws IOException { String[] bucketKeyFrom = splitPathToBucketAndKey(pathFrom, true); String[] bucketKeyTo = splitPathToBucketAndKey(pathTo, true); CopyObjectRequest copyRequest = new CopyObjectRequest(bucketKeyFrom[0], bucketKeyFrom[1], bucketKeyTo[0], bucketKeyTo[1]); this.amazonS3.copyObject(copyRequest); //Delete the source this.amazonS3.deleteObject(bucketKeyFrom[0], bucketKeyFrom[1]); }
@Override public void rename(String pathFrom, String pathTo) throws IOException { String[] bucketKeyFrom = splitPathToBucketAndKey(pathFrom, true); String[] bucketKeyTo = splitPathToBucketAndKey(pathTo, true); CopyObjectRequest copyRequest = new CopyObjectRequest(bucketKeyFrom[0], bucketKeyFrom[1], bucketKeyTo[0], bucketKeyTo[1]); this.amazonS3.copyObject(copyRequest); //Delete the source this.amazonS3.deleteObject(bucketKeyFrom[0], bucketKeyFrom[1]); }
AmazonS3 s3 = new AmazonS3Client(); String bucketName = "bucketName "; String key = "key.txt"; ObjectMetadata newObjectMetadata = new ObjectMetadata(); // ... whatever you desire, e.g.: newObjectMetadata.setHeader("Expires", "Thu, 21 Mar 2042 08:16:32 GMT"); CopyObjectRequest copyObjectRequest = new CopyObjectRequest() .WithSourceBucketName(bucketName) .WithSourceKey(key) .WithDestinationBucket(bucketName) .WithDestinationKey(key) .withNewObjectMetadata(newObjectMetadata); s3.copyObject(copyObjectRequest);
@Override public FileData copyHistory(String srcName, FileData destData, String version) throws IOException { try { CopyObjectRequest request = new CopyObjectRequest(bucketName, srcName, version, bucketName, destData.getName()); CopyObjectResult result = s3.copyObject(request); onModified(); return checkHistory(destData.getName(), result.getVersionId()); } catch (SdkClientException e) { throw new IOException(e); } }
@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.copyObject(copyObjectRequest); }
/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }