[英]AWS SDK for JavaScript v3 PutObjectCommand error 'A header you provided implies functionality that is not implemented'
I'm trying to upload a file with node.js from my client app (electron) to an S3 bucket in this manner:我正在尝试以这种方式将带有 node.js 的文件从我的客户端应用程序(电子)上传到 S3 存储桶:
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const s3Client = new S3Client({
region: 'eu-central-1',
credentials: {
accessKeyId: 'access',
secretAccessKey: 'secret',
},
});
const uploadFileToS3 = async (f) => {
const bucketParams = {
ACL: 'private',
Bucket: 'bucket',
Key: f.name,
Body: f.data,
ServerSideEncryption: 'AES256',
ContentType: 'image/png',
};
try {
return await s3Client
.send(new PutObjectCommand(bucketParams))
.then((result) => {
return process.send({
type: 'success',
fileName: f.name,
result,
});
});
} catch (erro) {
process.send({
type: 'error',
fileName: f.name,
error: erro,
});
}
};
process.on('message', (file) => {
uploadFileToS3(file);
});
I get the following error, that I'm unable to understand:我收到以下错误,我无法理解:
error: {
name: 'NotImplemented',
'$fault': 'client',
'$metadata': {
httpStatusCode: 501,
requestId: 'PXEBV6H4MX3',
extendedRequestId: 'yyyyyy',
attempts: 1,
totalRetryDelay: 0
},
Code: 'NotImplemented',
Header: 'Transfer-Encoding',
RequestId: 'PXEBV6H4MX3',
HostId: 'yyyyyy',
message: 'A header you provided implies functionality that is not implemented'
}
The file is a buffer generated with:该文件是通过以下方式生成的缓冲区:
fs.readFileSync(pth)
fs.readFileSync(pth)
Any idea of what could caused this error?知道是什么导致了这个错误吗?
Seems like the buffer created with看起来像创建的缓冲区
fs.readFileSync(pth)
fs.readFileSync(pth)
was rejected and I could only use a stream:被拒绝了,我只能使用 stream:
const readableStream = await createReadStream(Buffer.from(f));
const readableStream = await createReadStream(Buffer.from(f));
Maybe I'm wrong but it is possible that the actual SDK version is unable to accept a buffer yet, this could be the reason for that "missing functionality" message.也许我错了,但实际的 SDK 版本可能无法接受缓冲区,这可能是“缺少功能”消息的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.