簡體   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