使用生成的预签名 url 将文件上传到 minio 的请求中缺少字段

Missing fields in request to upload files to minio using the generated presigned url

我正在使用 Minio Server 来处理我的 nodejs API 中的文件,基本上是在本地模拟 s3。我生成了 Presigned Url 来直接上传图片。

Presign Url 生成工作正常,但是当我从 Postman 上传我的文件时,文件出现此错误:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>MissingFields</Code>
    <Message>Missing fields in request.</Message>
    <Key>records/marbles.jpg</Key>
    <BucketName>bucket</BucketName>
    <Resource>/bucket/records/marbles.jpg</Resource>
    <RequestId>16E442AB40F8A81F</RequestId>
    <HostId>0149bd16-e056-4def-ba82-2e91346c807c</HostId>
</Error>  

请求似乎包含所需的 headers as mentioned in this thread:

headers 是:

我也在 postman(Body>binary>select file) 中正确 select 文件:

我用于预签名 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  

而且效果很好。