我正在使用graphql-upload将文件从node.js graphql API上传到s3,
const { createReadStream, mimetype, filename } = file;
const fileStream = createReadStream();
const prefix = encodeURIComponent(folder) + '/';
const uploadParam = {
Bucket: bucket,
Key: `testing`,
Body: fileStream,
ContentType: mimetype,
};
await s3.send(new PutObjectCommand(uploadParam));
每次我上传,它显示这个错误
NotImplemented: A header you provided implies functionality that is not implemented
Code: 'NotImplemented',
Header: 'Transfer-Encoding',
我做错了什么?
1条答案
按热度按时间snz8szmq1#
问题的根本原因是缺少
ContentLength
。新版本的@aws-sdk/client-s3
无法单独通过graphql-upload
的流来查找文件大小。可能的解决方案:1.从前端单独传递文件大小,然后在
PutObjectCommand
处指定ContentLength
1.如果在
s3Client.send
调用时不知道文件大小,请使用@aws-sdk/lib-storage