In my Nextjs project I’m trying to copy files using (CopyObjectCommand).
Using @aws-sdk/client-s3: 3.616.0
The PutObjectCommand and DeleteObjectCommand are working fine. However, the CopyObjectCommand returns an error
Below is my code
// Copy S3 Object
export const copyS3Object = (sourceKey, destinationKey ) => {
try {
const bucket = process.env.AWS_S3_BUCKET;
const encodedSource = encodeURIComponent(`${bucket}/${sourceKey}`);
const params = {
Bucket: bucket,
CopySource: encodedSource,
Key: destinationKey,
};
const command = new CopyObjectCommand(params);
const data = await s3Client.send(command);
return { status: 'success' };
} catch (error) {
console.error("Error in copyS3Object:", error.message);
console.error("Stack trace:", error.stack);
throw new Error("Failed to copy S3 object");
}
},
});```
// How I call it
const newKey = courses/${courseId}/${variant.name}/${variant.filename}
;
const oldKey = courses/temp/${variant.name}/${variant.filename}
;
await copyS3Object({ sourceKey: oldKey, destinationKey: newKey });
Error : A header you provided implies functionality that is not implemented
[The error](https://i.sstatic.net/jn5MsPFd.png)
I have tried using an encoded and non encoded versions of the key and copySource. Also tried hard coding those values and still I get the error. I am using javascript and not Typescript on this project.
Kingsley Nyaosi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.