[英]How to upload an object using presigned URL along with tags in s3 aws-sdk-ruby v3
[英]Upload stream to Amazon s3 using nodejs SDK v3
我想使用 AWS SDK v3 將 stream 上傳到 s3。
此處記錄的 PutObjectRequest 應該接受 ReadableStream,但每次我收到錯誤NotImplemented: A header you provided implies functionality that is not implemented
- 報告的 header 是Transfer-Encoding
。
This SO article建議我提供一個空體,但它應該接受ReadableStream(Archiver提供一個Transform流)。
我創建了一個最小的(非)工作示例。 我也嘗試過將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()
問題是 Archiver 庫使用來自 Node 10 的 static 版本的readable-stream
,它與 AWS SDK 版本不兼容。
當它通過管道傳輸到 Archiver 實例時,它失敗了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.