简体   繁体   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'

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.

相关问题 Aws SDK:集成 AWS v3 时出现 CredentialsProviderError Javascript SDK - Aws SDK: CredentialsProviderError while integrating AWS v3 Javascript SDK 使用 AWS javascript SDK,V3,是否有等效的凭证提供程序链? - Using the AWS javascript SDK, V3, is there a credentials provider chain equivalent? 将 CognitoIdentityCredentials 迁移到模块化 AWS SDK for JavaScript (v3) - Migrating CognitoIdentityCredentials to modular AWS SDK for JavaScript (v3) 为 AWS 设置 customBackoff SDK JavaScript V3 重试 - Set customBackoff for AWS SDK JavaScript V3 retries serverless-s3-local 插件和@aws-sdk/client-s3 使用 PutObjectCommand 返回错误 - serverless-s3-local plugin and @aws-sdk/client-s3 returns an error with PutObjectCommand AWS XRay 与 AWS SDK v3 for NodeJS - AWS XRay with AWS SDK v3 for NodeJS 使用 aws sdk v3 调试 ENOTFOUND 错误 - Debugging ENOTFOUND error using aws sdk v3 将带有预签名 url 的分段上传从 aws javascript sdk v2 迁移到 v3 - migrate multipart upload with presigned urls from aws javascript sdk v2 to v3 AWS SDK JavaScript - 我们计算的请求签名与您提供的签名不匹配 - AWS SDK JavaScript - The request signature we calculated does not match the signature you provided AWS SDK v3 for NodeJS 不调用 Lambda 也不返回错误 - AWS SDK v3 for NodeJS doesn't call Lambda nor returns error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM