Skip to content

Adding ContentType to S3Client's 'PutObjectCommand' gives 'SignatureDoesNotMatch' Error #5268

@henryson

Description

@henryson

Checkboxes for prior research

Describe the bug

Looks like the exact same issue as in: #1916 but I still have the same problem. (The page asked me to create a new issue).

My versions:

"@aws-sdk/client-s3": "^3.420.0", "@aws-sdk/lib-storage": "^3.420.0", "@aws-sdk/s3-request-presigner": "^3.420.0"

My code:

import cuid from 'cuid'
import { S3, PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
import config from "../config/config"

const client = new S3({
    region: "eu-north-1",
    endpoint: config.myUrl,
    credentials: {
        accessKeyId: config.myAccess,
        secretAccessKey: config.mySecret,
    }
})

const signedUrl = async (args: any) => {
    const fileId = cuid()
    const filetype = args.filetype
    const filename = args.filename
        .replace(/([Ì]|[^0-9a-öA-Ö.\s])/g, '')
        .normalize('NFKD')
        .replace(/([\u0300-\u036f]|[^0-9a-zA-Z.\s])/g, '')
    const command = new PutObjectCommand({ Key: fileId + "/" + filename, Bucket: config.myBucket, ContentType: filetype, ContentLength: 1 })
    const url = await getSignedUrl(client, command, { expiresIn: 15 * 60 })
    return { id: fileId, name: filename, url, type: filetype }
}

From signed URL:

X-Amz-SignedHeaders | content-length;host

I do not get it how this can have been fixed in 3.3.0? Is it different when using the presigned URL API?

Thanks in advance for any help!

Cheers, Josef

SDK version number

"@aws-sdk/client-s3": "^3.420.0", "@aws-sdk/lib-storage": "^3.420.0", "@aws-sdk/s3-request-presigner": "^3.420.0"

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

node 18.12.1

Reproduction Steps

import cuid from 'cuid'
import { S3, PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
import config from "../config/config"

const client = new S3({
    region: "eu-north-1",
    endpoint: config.myUrl,
    credentials: {
        accessKeyId: config.myAccess,
        secretAccessKey: config.mySecret,
    }
})

const signedUrl = async (args: any) => {
    const fileId = cuid()
    const filetype = args.filetype
    const filename = args.filename
        .replace(/([Ì]|[^0-9a-öA-Ö.\s])/g, '')
        .normalize('NFKD')
        .replace(/([\u0300-\u036f]|[^0-9a-zA-Z.\s])/g, '')
    const command = new PutObjectCommand({ Key: fileId + "/" + filename, Bucket: config.myBucket, ContentType: filetype, ContentLength: 1 })
    const url = await getSignedUrl(client, command, { expiresIn: 15 * 60 })
    return { id: fileId, name: filename, url, type: filetype }
}

Observed Behavior

X-Amz-SignedHeaders | content-length;host (from presigned URL)

Expected Behavior

X-Amz-SignedHeaders | content-length;host;content-type

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2This is a standard priority issueworkaround-availableThis issue has a work around available.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions