简体   繁体   中英

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:

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)

Any idea of what could caused this error?

Seems like the buffer created with

fs.readFileSync(pth)

was rejected and I could only use a stream:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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