How to retrieve metadata using @cloudinary/url-gen
Hello,
I'm trying to get the image title and alt tags using https://www.npmjs.com/package/@cloudinary/url-gen but I don't see anything mentioned about this in the documentation. Is it really the only possible way to do it by using the NodeJS API with context option set to true as described here https://cloudinary.com/documentation/admin_api#get_resources?
I would really like to avoid having separate route just to get image metadata in my React NextJS application.
Thank you in advance!
-
Hi Yuriy,
The project is associated with frontend SDKs so you won't be able to do Admin API requests. However, an alternative you can use is by using the client-side assets list.
This requires tagging your assets but you could use it to get back those metadata without a backend.
Hope that helps.
Best,
Loic
0 -
Thank you, Loic! This sounds a bit complex for something that I thought should be coming out of the box. Perhaps a separation could be added for custom metadata fields and standard alt/title fields and make them available through the API?
Have a great day,
Yuriy0 -
Hey Yuriy,
The reason you can't perform admin API actions from the client-side is because of security mesaures.
The admin API is intended for administrative actions including destructive operations, retrieving internal information about your assets and ones that can modify many different aspects of your account. As such, such requests require authentication credentials to be passed within the request. When making client-side requests, this information is of course publicly exposed to the client visiting your website/application. Therefore, using these methods via the client would be a major security breach.With that being said, as Loic mentioned, we introduced other approaches for retrieving some limited information, using a less-intrusive method, which can only return details of assets you meant to be returned by tagging them with specific tags. It might be a bit time-consuming to retrospectively tag existing assets on your cloud using the Explicit API method or the UI, but with regard to new assets uploads, you can just make sure that you change your upload calls to include the relevant tags in the requests' parameters.
I'm afraid that currently, all information retrieval API methods are part of the Admin/Search APIs which require the above-mentioned authentication which is not client-side suitable. The only feasible approach at the moment would be using the list API. You can open a direct support ticket with us if you need our assistance with writing the script that will tag all existing images based on some pre-defined criteria.
Best,
Raz0
Post is closed for comments.
Comments
3 comments