Reputation: 605
Java 8 here. I have an S3 bucket (myapp-bucket
) with the following folder substructure:
/artwork
/upload
/staging
Here's what the myapp-bucket/artwork
folder looks like:
I have software that uploads image files to the /upload
folder, and then another app that I'm writing is supposed to process that image and copy it over to the /staging
folder. The code I have to perform this S3 copy is as follows:
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(
bucketName,
objectKey,
destinationBucket,
destinationKey
);
log.info(
"copying object from s3://{}/{} to s3://{}/{}",
bucketName,
objectKey,
destinationBucket,
destinationKey
);
// Constructed via
AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
amazonS3.copyObject(copyObjectRequest);
When this runs, I see the following log output I see is:
[main] DEBUG com.me.myapp.ImageProcessor - copying object from s3://myapp-bucket/artwork/upload/rlj_amp244001_270.jpeg to s3://myapp-bucket/artwork/staging
But the final state of the myapp-bucket/artwork
folder looks like this:
So it looks like, instead of copying myapp-bucket/artwork/upload/<theImageFile>
to the myapp-bucket/artwork/staging/
directory, its creating a new file directly under /artwork
and naming it staging
, and likely copying the binary contents of the image into that staging file. Where am I going awry?! I just want to end up with myapp-bucket/artwork/staging/<theImageFile>
-- thanks in advance!
Upvotes: 2
Views: 1244
Reputation: 1815
S3 doesn't have folders/directories - it's just sugar over a flat storage. So your destinationKey
should look like artwork/staging/rlj_amp244001_270.jpeg
Upvotes: 7