I have a script in Typescript that works for reading files from S3 but now want to read 2 files, concatinate the output of both and then print as a total_string
.
var total_string = '';
var files = ['file1.txt', 'file2.txt'];
for (var file of files) {
var s3_params = {
Bucket: 'bucket1',
Key: file
}
s3.getObject(s3_params, function(err, data) {
if (err) {
console.log("\nError!!!\n");
console.log(err, err.stack);
}
else {
console.log("Data in a file:", data);
let objectData = data.Body.toString('utf-8');
console.log("objectData:\n", objectData);
total_string = total_string.concat(objectData);
}
});
}
console.log(total_string);
Currently - total_string
is printing before other ones are executed so need to convert above code into Promise I believe..