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(
I prefer Buffer.from(data.Body).toString('utf8')
. It supports encoding parameters. With other AWS services (ex. Kinesis Streams) someone may want to replace 'utf8'
encoding with 'base64'
.
new AWS.S3().getObject(
{ Bucket: this.awsBucketName, Key: keyName },
function(err, data) {
if (!err) {
const body = Buffer.from(data.Body).toString('utf8');
console.log(body);
}
}
);