I wrote the following code to upload files to amazon s3.
var upload = async function() {
var uploadURLs = []
for (var i = 0; i < files.length; i++) {
fs.readFile(filePath, (error, content) => {
s3.putObject({
Bucket: bucketName,
Key: key,
Body: content
}, function(err, data){
.....
if (uploadCount == files.length - 1) {
uploadURLs = allUrls;
}
}
}
return uploadURLs
}
The code is working fine but the returned array uploadURLs
is empty where allUrls
is not. Do you have an idea on how to solve the issue? Id I refer to this post I do not see any reason why this should not work.