How to get Embedded Metadata (EXIF) from an image?

wildly_unhappy
wildly_unhappy Member Posts: 2
edited November 2023 in Developer APIs

I want to get all image from a folder using:

const photoList = await cloudinary.v2.api.resources(
    {
      type: "upload",
      prefix: "<FOLDER_NAME>",
      metadata: true,
    },
    function (error, result) {
      console.log(result, error);
    },
  );

I can see the EXIF data from my images in the DAM and I need the DateTimeOriginal from the image's metadata in the response for sorting purposes.

The only thing I find about this topic, is an article from 2012 about EXIF data which says

**Update March 2017: The exif parameter has been deprecated. The exif data can now be extracted using the image_metadata parameter.

So I went ahead and used image_metadata: true in the code above. But this doesn't change anything in the response. The article is quite misleading with this statement.

Is there any way to still get the EXIF data (or in my case at least that specific piece of DateTimeOriginal ) of an image?

TIA, Best wishes, Fabian

Answers

  • Tom
    Tom Member, Cloudinary Staff Posts: 108

    Hi @wildly_unhappy,

    Thanks for reaching out. 

    Unfortunately, the resources API does not support media_metadata (formerly `image_metadata`) parameter per https://cloudinary.com/documentation/admin_api#get_resources.

    You will need to use resource by public ID API (https://cloudinary.com/documentation/admin_api#get_details_of_a_single_resource_by_public_id) by specifying `media_metadata: true` and you will see EXIF data in the response.

    However, the above requires making a request per public_id so you can instead use Search API (https://cloudinary.com/documentation/admin_api#search_for_resources) by specifying with_field('image_metadata') (media_metadata is not yet supported on Search API) and you should see EXIF data for all the assets in the response.

    Please let me know if you have any other questions or queries.

    Kind Regards,

    Thomas

  • wildly_unhappy
    wildly_unhappy Member Posts: 2

    Hey Thomas,

    these actually give me the data I need. The problem is, the Search API is incredibly unstable with folders/asset_folders. With the resources API, the prefix works perfectly fine, the new API endpoint by_asset_folder works perfectly. But with the Search API I cannot get anything working folder-wise.

    /resources/search?expression="folder=myFolder"&with_field=image_metadata

    This finds images everywhere but only randomly the one from the actual folder I am searching in.