javascript - tar 并将多个文件上传到 Node.js 中的 S3
问题描述
我在不同的位置有两个文件,我想压缩(tar.gz)并上传到 S3 存储桶。
文件的当前位置在我的文件系统中如下所示
File 1: src/textFile/sample.txt
File 2: src/jsonData/sample.json
我需要将上述两个文件存储在一个压缩文件夹中并将其上传到 S3。tar.gz
有没有一种方法可以直接流式传输到 S3 而无需在文件系统中创建其他文件?
我正在阅读有关使用tar-stream
ortar-fs
包的信息,但不确定这是否是正确的方法。
我现在的 S3课
class AwsS3Service {
private config ={
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.SECRET_ACCESS_KEY,
region: "us-east-1"
}
FOLDER = "zip";
BUCKET = "xxxxxxxx";
private getBucket;
constructor(){
this.getBucket = new S3(this.config);
}
public async uploadFile(file: Buffer, key: string): Promise<Boolean>{
try{
const params = {
Bucket: this.BUCKET,
Key: this.FOLDER + key,
Body: file,
ACL: 'private'
}
const data = await this.getBucket.upload(params);
}catch(err){
console.log(`Couldn't upload the file: ${err.message}`);
return false;
}
return true;
}
}