Node.js aws s3 sdk v3在放置对象时显示错误

5rgfhyps  于 2023-04-11  发布在  Node.js
关注(0)|答案(1)|浏览(286)

我正在使用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',

我做错了什么?

snz8szmq

snz8szmq1#

问题的根本原因是缺少ContentLength。新版本的@aws-sdk/client-s3无法单独通过graphql-upload的流来查找文件大小。可能的解决方案:
1.从前端单独传递文件大小,然后在PutObjectCommand处指定ContentLength
1.如果在s3Client.send调用时不知道文件大小,请使用@aws-sdk/lib-storage

相关问题