I'm facing issues with npm exiftool usage. (https://www.npmjs.com/package/exiftool) I'm attempting to perform some tasks using it.
- Iterate through image files in a specific folder
- Retrieve 'xpKeywords' data of each image file
- Write the file storing data
Below is my code snippet.
const fs = require('fs');
const exif = require('exiftool');
const folderName = 'testImages';
const inputPath = `/Users/myName/Project/project/${folderName}`;
const files = fs.readdirSync(inputPath, 'utf8');
let data = [];
(async () => {
let promises = [];
files.forEach(file => promises.push(fs.readFileSync(`${inputPath}/${file}`)));
let results = await Promise.all(promises);
for(let [index, result] of results.entries()) {
let datum = await getMetadata(result, index);
console.log("out");
data.push(datum);
}
fs.writeFileSync('outputData/metaData.json', JSON.stringify(data, null, 4), (error) => {
console.log('Error Occurred');
});
})();
async function getMetadata(result, index) {
console.log(`get metadata ${index}`);
await exif.metadata(result, (err, metadata) => {
return {
name: files[index],
hashTags: metadata.xpKeywords
};
});
}
Upon executing this code, the generated metaData.json file does not match my expectations.
[ null, null, null, null, null, null ]
I suspect there might be an issue with the use of async functions within the getMetadata function.