简体   繁体   English

使用 nodejs SDK v3 将 stream 上传到 Amazon s3

[英]Upload stream to Amazon s3 using nodejs SDK v3

I would like to upload a stream to s3 using the AWS SDK v3.我想使用 AWS SDK v3 将 stream 上传到 s3。

The PutObjectRequest as documented here should accept a ReadableStream, but every time I receive the error NotImplemented: A header you provided implies functionality that is not implemented - the header reported is Transfer-Encoding . 此处记录的 PutObjectRequest 应该接受 ReadableStream,但每次我收到错误NotImplemented: A header you provided implies functionality that is not implemented - 报告的 header 是Transfer-Encoding

This SO article suggests that I'm providing an empty body, but it's supposed to accept ReadableStream (Archiver provides a Transform stream). This SO article建议我提供一个空体,但它应该接受ReadableStream(Archiver提供一个Transform流)。

I have created a minimal (non) working example.我创建了一个最小的(非)工作示例。 I have also tried putting client.send() with a callback instead, but with the same response.我也尝试过将client.send()与回调一起使用,但响应相同。

import fs from 'fs'
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
import archiver from 'archiver'

async function run() {
  const archive = archiver('zip')

  const client = new S3Client({ region: process.env.AWS_REGION })

  // create a stream destination for aws
  // also pipe to aws
  try {
    const command = new PutObjectCommand({
      Bucket: process.env.AWS_DEFAULT_BUCKET,
      Key: 'testupload.zip',
      // set the content type as we're streaming it
      ContentType: 'application/zip',
      // body should take a readable stream
      Body: archive,
    })
    client.send(command, (err, data) => {
      console.log(data)
    })
  } catch (err) {
    console.error('Error uploading package to S3')
    console.error(err)
    res.status(501).json({ message: 'Error configuring upload to s3' })
  }

  archive.file('/fixtures/harambe.jpg', { name: 'harambe.jpg' })

  archive.finalize()
}

run()

The issue is that the Archiver library uses a static version of readable-stream from Node 10, which is not compatible with the AWS SDK version.问题是 Archiver 库使用来自 Node 10 的 static 版本的readable-stream ,它与 AWS SDK 版本不兼容。

When it pipes to the Archiver instance, it fails.当它通过管道传输到 Archiver 实例时,它失败了。

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

相关问题 如何使用预签名的 URL 以及 s3 aws-sdk-ruby v3 中的标签上传 object - How to upload an object using presigned URL along with tags in s3 aws-sdk-ruby v3 AWS s3 V3 Javascript SDK stream 来自存储桶的文件 (GetObjectCommand) - AWS s3 V3 Javascript SDK stream file from bucket (GetObjectCommand) 使用nodejs aws sdk 将生成的pdf上传到AWS S3 - Upload pdf generated to AWS S3 using nodejs aws sdk 用于 nodejs 的 AWS SDK v3,如何获取 s3 存储桶的标签? - AWS SDK v3 for nodejs, how to get tags of an s3 bucket? 如何使用 Jest 在 Nodejs 中模拟 Amazon DynamoDB v3? - How to mock an Amazon DynamoDB v3 in Nodejs using Jest? 如何使用 AWS SDK V2 为 Amazon S3 配置终端节点? - How do you configure the endpoint for Amazon S3 by using the AWS SDK V2? 使用访问密钥和秘密将文件上传到 Amazon S3,而不使用 SDK - Upload file to Amazon S3 with access key and secret, without using SDK 使用 AWS SDK (S3.putObject) 上传一个 Readable stream 到 S3 (node.js) - Using AWS SDK (S3.putObject) to upload a Readable stream to S3 (node.js) S3 为使用 aws-sdk v3 预签名的 PutObject 命令 url 提供 SignatureDoesNotMatch 错误 - S3 gives SignatureDoesNotMatch error for PutObject command pre-signed url using aws-sdk v3 使用 multer-s3 nodejs 将图像上传到 amazon s3 - Uploading image to amazon s3 using multer-s3 nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM