Download xlsx from S3 and parse it

前端 未结 5 1707
星月不相逢
星月不相逢 2021-01-05 10:33

I need a service to download an excel file from Amazon S3, then parse with node-xlsx

The problem is that I can\'t get xlsx to parse the file. When I try to read back

5条回答
  •  春和景丽
    2021-01-05 11:01

    This is how you can read a file from S3 nodejs and keep it in memory without first writing the file to some location on disk. It can be used with a combination of S3 and AWS Lambda so that you don't have to write the files to some location on the Lambda.

    Remember this processes is asynchronous.

       var params = {
            Bucket: "",
            Key: ""
        };
    
        var file = s3.getObject(params).createReadStream();
        var buffers = [];
    
        file.on('data', function (data) {
            buffers.push(data);
        });
    
        file.on('end', function () {
            var buffer = Buffer.concat(buffers);
            var workbook = xlsx.parse(buffer);
            console.log("workbook", workbook)
        });
    

提交回复
热议问题