在 Node.js 中 Tar 并将多个文件上传到 S3

问题描述

我在不同的位置有两个文件要压缩 (tar.gz) 并上传到 S3 存储桶。

文件在我的文件系统中的当前位置如下

File 1: src/textFile/sample.txt
File 2: src/jsonData/sample.json

我需要将上述两个文件存储在一个压缩文件夹中,然后将其上传到 S3。有没有一种方法可以直接流式传输到 S3,而无需在文件系统中创建额外的 tar.gz 文件

我正在阅读有关使用 tar-streamtar-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;
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)