gpt4 book ai didi

javascript - 如何在 node.js 中创建流?

转载 作者:行者123 更新时间:2023-11-30 20:51:08 24 4
gpt4 key购买 nike

我有一个将作为参数的函数:

  startUpload(stream, filename) {
const upload = this.s3.upload({
Bucket: this.bucket,
ServerSideEncryption: 'aws:kms',
SSEKMSKeyId: this.s3SseKmsKeyId,
Key: `${this.key}/${filename}`,
Body: stream
}, { partSize: 50 * 1024 * 1024, queueSize: 1 });
}

如何创建流并向其中写入数据?

最佳答案

下面的代码适合我

const AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: process.env.AWS_KeyId,
secretAccessKey: process.env.AWS_secret,
// region:process.env.AWS_region
});

const s3 = new AWS.S3({ signatureVersion: 'v4', })
var multer = require('multer')
var multerS3 = require('multer-s3')
var photoBucket = new AWS.S3({
params: {
Bucket: 'carwhapps'
}
})
// let source is like req.files.filename or test with static file like ./public/test.jpg
photoBucket.upload({
ACL: 'public-read',
Body: fs.createReadStream(source),
Key: filename,
ContentType: 'application/octet-stream' // force download if it's accessed as a top location
},(err, response)=>{
console.log(err, response)

})

关于javascript - 如何在 node.js 中创建流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48172367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com