aws javascript sdk v3 - 签名不匹配错误

aws javascript sdk v3 - signature mismatch error

我可以按照 as described in this section 的步骤生成预签名的 url,所以我想测试上传特定图像 marble.jpg 我尝试使用 postman 来测试上传。所以,我复制了预签名的 url 并使用 PUT 请求点击了 endpoint,但我得到了这个错误:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
    <Key>records/marble_cave.jpg</Key>
    <BucketName>bucket</BucketName>
    <Resource>/bucket/records/marble.jpg</Resource>
    <RequestId>17E3999B521ABB65</RequestId>
    <HostId>50abb07a-2ad0-4948-96e0-23403f661cba</HostId>
</Error>

已设置以下资源:

所以,问题是:

我用于预签名 url 生成的代码是:

import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
const s3Client = new S3Client({
        region: 'us-east-1',
        credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin',
    },
        endpoint: http://172.21.0.2:9000,
        forcePathStyle: true,
    });
  
const bucketParams = {
        Bucket: 'myBucket',
        Key: `marbles.jpg`,
};  
  
const command = new PutObjectCommand(bucketParams);

const signedUrl = await getSignedUrl(s3Client, command, {
        expiresIn: 10000,
})  

解决方案可能和我的一样,所以简单地复制答案:

我正在尝试更改端口,当我仅使用本地主机进行 url 生成时 put 命令似乎有效

所以,在上面:

new S3Client({
        region: 'us-east-1',
        credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin',
    },
        endpoint: http://172.21.0.2:9000,
        forcePathStyle: true,
    });  

我使用:

new S3Client({
        region: 'us-east-1',
        credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin',
    },
        endpoint: http://172.21.0.2, // or 127.0.0.1
        forcePathStyle: true,
    });  

注意,我没有使用任何端口号,所以默认是80

如果您使用 docker-compose 添加此配置:

. 
.
.
ports:  
  - 80:9000  

而且效果很好。