[英]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.