PutObjectCommand always gives 400 error

no matter what i try to do my code always gives a 400 error trying to upload to the object storage using AWS V3 and V2 for javascript / node.

here is our code:

const s3 = new S3Client({
credentials: {
accessKeyId: MWSB_ENVIRONMENT_CONFIG.S3_ACCESSKEY,
secretAccessKey: MWSB_ENVIRONMENT_CONFIG.S3_SECRETACCESSKEY,
},
endpoint: 'https://' + bucket.hostname.replace(bucket.label + '.', ''),
region: bucket.region,
});

const command = new PutObjectCommand({
        Bucket: bucket.label,
        Key: 'sander.json,
        Body: JSON.stringify({sander:'test'}, null, 2),
        ContentType: mime.getType(uploadFilename),
        ACL: 'public-read',
      });
      await s3.send(command);

endpoint: https://nl-ams-1.linodeobjects.com
mime: application/json
bucket: gurdeep-3216-3216-ser
region: nl-ams

1 Reply

TLDR; I believe you are missing a quotation-pair to close out your key:

Key: 'sander.json,
...

As opposed to that line being closed:

Key: 'sander.json',
...

All of the code tailing that open-quotation appears to be highlighted yellow in the markdown further supporting that this may be the issue.


Application-level API use is a bit outside of my general experience, but I can hopefully provide some helpful "outside eyes" on your error nonetheless. 400 Errors specify that your submitted command is an invalid request, so let's break apart your command a bit:

API Token:
Ensure that your current API credentials are both correct and grant the necessary access permissions to execute your API call.

Endpoint Address/Bucket:
Ensure that all references of our OBJ endpoints is accurate and formatted correctly. It's my understanding that you may need to condense the URL in the API call to *https://nl-ams-1.linodeobjects.com*.

API Syntax:
In the past, we have recommended following the S3 documentation to ensure your commands match what the API expects. For more details, be sure to reference the following Docs:

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct