繁体   English   中英

AWS SDK for JavaScript v3 PutObjectCommand error 'A header you provided implies functionality that is not implemented'

[英]AWS SDK for JavaScript v3 PutObjectCommand error 'A header you provided implies functionality that is not implemented'

我正在尝试以这种方式将带有 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);
});

我收到以下错误,我无法理解:

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'
  }

该文件是通过以下方式生成的缓冲区:

fs.readFileSync(pth)

知道是什么导致了这个错误吗?

看起来像创建的缓冲区

fs.readFileSync(pth)

被拒绝了,我只能使用 stream:

const readableStream = await createReadStream(Buffer.from(f));

也许我错了,但实际的 SDK 版本可能无法接受缓冲区,这可能是“缺少功能”消息的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM