amazon s3 – Java AWS SDK copyObject is not copying the content to another folder

I have a use case which is like this :
I need to copy a file from one folder to another folder in the same bucket. To that end , I am using the below code :

    CopyObjectRequest copyObjectRequest = CopyObjectRequest.builder()
                    .sourceBucket(bucketName)
                    .sourceKey(s3Object.key()) // -- this key is like this : ABB/PP/RR/KK1/TT/YY/II/myFile.dat
                    .destinationBucket(bucketName)
                    .destinationKey("ABB/PP/RR/KK2/II/"+filename)
                    .build();

    s3Client.copyObject(copyObjectRequest);

However , when I execute this code , I see a file is getting generated of the same name in the destination folder but the content is not the content of the original file . Rather , it seems to have the destination key as the content .

Can someone let me know how to get the copy done in such a way so that all the content from the original file gets copied ?

Read more here: Source link