0

I have a bucket which has versioning enabled. In my ReactJS app, I need to upload files to the bucket and receive the new object metadata. I use S3 Client with PutObjectCommand to do the upload. The documentation here states:

Versioning

If you enable versioning for a bucket, Amazon S3 automatically generates a unique version ID for the object being stored. Amazon S3 returns this ID in the response. When you enable versioning for a bucket, if Amazon S3 receives multiple write requests for the same object simultaneously, it stores all of the objects.

So, I expect to receive a VersionId. But not only this field is undefined, but also other fields like requestId or `cfId.

Here is my module code:

import {
    PutObjectCommand,
    S3Client
} from '@aws-sdk/client-s3';

const S3_BUCKET_NAME = process.env.S3_BUCKET_NAME;
const AWS_REGION = process.env.AWS_REGION;
const AWS_ACCESS_KEY = process.env.AWS_ACCESS_KEY;
const AWS_SECRET_KEY = process.env.AWS_SECRET_KEY;

const client = new S3Client({
    region: AWS_REGION,
    credentials: {
        accessKeyId: AWS_ACCESS_KEY,
        secretAccessKey: AWS_SECRET_KEY
    }
});

const uploadToS3 = async function (fileToUpload) {
    const data = await fileToUpload.arrayBuffer();

    const params = {
        Bucket: S3_BUCKET_NAME,
        Key: fileToUpload.name,
        Body: data
    };

    const command = new PutObjectCommand(params);
    const result = await client.send(command);

    console.log(result); // requestId: undefined, extendedRequestId: undefined, cfId: undefined
    console.log(`VersionId: ${result.VersionId}`); // VersionId: undefined
}

export default {
    uploadToS3
}

Have I missed anything here?

Persian Brat
  • 394
  • 2
  • 13

0 Answers0