I use node-async-loop
npm package to push EXIF image data. this EXIF image gets on AWS S3 storage in a loop. and then push this data into an array. but the node-async-loop
resolve result before pushing the image data into an array. but missing the last image to push EXIF data in the array. so, how can resolve the result before push data?
I put my code in below:
static getAWSKey(data) {
var result = [];
var totalCount = data.Contents.length;
var counter = 1;
return new Promise(function(resolve, reject) {
asyncLoop(data.Contents, function (item, next) {
console.log('item.....'+JSON.stringify(item));
var urlParams = {Bucket: 'bucketName', Key: item.Key};
s3Bucket.getSignedUrl('getObject', urlParams, function(err, url){
request.get(url, function (err, res, body) {
new ExifImage(body, function (error, exifData) {
if (error) {
console.log('Error: '+ error.message);
result.push(error.message);
} else {
result.push(exifData);
console.log("RESULT:"+JSON.stringify(result));
}
next();
});
});
});
counter++;
if(counter > totalCount) {
console.log('proc succ: finish');
resolve(result);
}
});
});
}
please, any one can help me. thanks
I use asyncLoop
its work but my loop start position is 1. so, my last record is missed by asyncLoop
. so, don't display the last record.
a second thing is I put below function in another method it's work.
new ExifImage(body, function (error, exifData) {
if (error) {
console.log('Error: '+ error.message);
result.push(error.message);
} else {
result.push(exifData);
console.log("RESULT:"+JSON.stringify(result));
}