nathanpeck / exiftool

A Node.js wrapper around exiftool, providing metadata extraction from numerous audio, video, document, and binary filetypes
MIT License
81 stars 26 forks source link

can we run exiftool synchronously. #20

Open supreetssethi opened 6 years ago

supreetssethi commented 6 years ago

Hi there, I am trying to dynamically get file details and i want to store it in db. When i am trying to run exif. it runs asynchronously so i couldn't get the exact mapping of file name and file metadata.

can you please help me out with this.

paddotk commented 4 years ago

I have the same issue too, although I'm not sure to what extent this is a sync/async issue or an exiftool issue. Any help would be appreciated.

What I'm trying to do is the following. I have a function getExifData which calls exiftool's method to fetch the exif data. I then need the result of that to continue with.

getExifData = async () => {
  const meta = exif.metadata('myfile.mp4', (err, metadata) => {
    if (err) {
       throw err;
       return {};
     } else {
         return metadata;
      }
   });
  return await meta;
}
myFunction = ()  => {
  const exifData = this.getExifData();
  const extension = exifData.category; // This needs the promise from exifData to be resolved
}

Because getExifData needs to be an async function, the second line in myFunction executes before the promise is resolved. I cannot make myFunction async, because the function that calls that would get the same issue.

What should I do here, if this is at all possible with exiftool?