Read file from aws s3 bucket using node fs

后端 未结 11 806
逝去的感伤
逝去的感伤 2020-12-07 21:37

I am attempting to read a file that is in a aws s3 bucket using

fs.readFile(file, function (err, contents) {
  var myLines = contents.Body.toString().split(         


        
11条回答
  •  忘掉有多难
    2020-12-07 22:19

    Since you seem to want to process an S3 text file line-by-line. Here is a Node version that uses the standard readline module and AWS' createReadStream()

    const readline = require('readline');
    
    const rl = readline.createInterface({
        input: s3.getObject(params).createReadStream()
    });
    
    rl.on('line', function(line) {
        console.log(line);
    })
    .on('close', function() {
    });
    

提交回复
热议问题