I have a S3 bucket called "Test1" and another S3 bucket called "Test2". There are three sub folders inside Test2. Name of the sub-folders are "RCA-test1/", "RCA-Test2/", "RCA-Test3/". I want to move the file from "Test1" bucket to Test2 bucket sub folder "RCA-test1". This is my code to achieve this:
var listObjectsRequest = new Amazon.S3.Model.ListObjectsV2Request
{
BucketName = sourceBucketName
};
var listObjectsResponse = await sourceS3Client.ListObjectsV2Async(listObjectsRequest);
foreach (var s3Object in listObjectsResponse.S3Objects)
{
if(!s3Object.Key.Contains("JSON"))
{
AmazonS3Client S3Client = new(accessKeyId.ToString(), secretAccessKey, RegionEndpoint.USWest2);
await S3Client.CopyObjectAsync(sourceBucketName, s3Object.Key, destinationBucketName, s3Object.Key);
}
The above code copies the file from the source bucket to the destination bucket, but it does not copy the file in the subfolder. I tried to rewrite the code like this so that the file can be moved to the destination bucket:
await S3Client.CopyObjectAsync(sourceBucketName, s3Object.Key, destinationBucketName + "/" + "RCA-test1/" , s3Object.Key);
when I ran the code, I got this error:
Amazon.S3.AmazonS3Exception: 'The request signature we calculated does not match the signature you provided. Check your key and signing method.'.
Not sure, what am I doing wrong. Any help will be highly appreciated.