在请求中缺少字段,以将文件上传到Minio使用生成的预设URL
我使用 Minio Server 来处理 Nodejs API 中的文件,基本上是在本地模拟 s3。我生成了 Presigned Url 来直接上传图像。
Presign Url Generation 工作正常,但是当我从 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>
该请求似乎包含所需的标头 如本帖所述:
标题为:
并且我还在中正确选择了文件postman(Body>binary>选择文件
) :
我用于预签名 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,
})
I'm using Minio Server to handle files in my nodejs API, basically to emulate s3 locally. I generated Presigned Url to upload images directly.
Presign Url Generation works fine but when I upload my file from Postman the file it gives me this error:
<?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>
The request seems to contain the required headers as mentioned in this thread:
the headers are:
and I also select the file properly in postman(Body>binary>select file
) :
The code I use for presigned url generation is:
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,
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在尝试和更改端口,
put
命令似乎在我仅将本地主机用于URL生成时可以正常工作,因此,在以上:
我使用:
注意,我没有使用任何端口号,因此,默认值为
80
,如果您使用
Docker-Compose
添加此配置:它可以正常工作。
I was trying and changing ports, and the
put
command seems to work when I use only local host for url generationso, in this above:
I use:
Note, I haven't used any port number, so the default is
80
If you're using
docker-compose
add this config:and it works fine.