Cloudinary Nodejs SDK - add_context method
I have been trying to add contextual data to uploaded assets but I keep getting a result of a empty public_ids
import { v2 as cloudinary } from 'cloudinary'
cloudinary.config({
cloud_name: '******',
api_key: '********',
api_secret: '********',
secure: true
});
const public_id = "knr1edxngugcejvihruz"
await cloudinary.uploader.add_context("alt=My image❘caption=Profile image", [public_id], (err, res) => {
if(err) return console.log(err)
console.log(res)
});
Console log:
{ public_ids: [] }
-
Hi Joe,
You can add contextual metadata to an existing asset in your Media Library by using the Admin API update method. For example:
cloudinary.api.update("sample_public_id",
{
type: "upload",
context: {
caption: "YourCaptionDataHere"
}
}, function(error, result) {console.log(result); } );Hope this helps.
-
Hi Eric,
Thank you for your help. I tried changing the method as you suggested, but now I am getting an error. It saying the resource was not found with that public id, which is clearly not the case.
To give a quick background I am trying to build a cloud function which gets triggered by Cloudinary's Notify webhook and uploads the newly uploaded video asset to Facebook's video endpoint and gets a unique "id" from facebook which then I would like to attach as the contextual or metadata tot he cloudinary asset.
**Edit: I might be missing the resource_type param, checking now...
{ message: 'Resource not found - jk8pp4lygnt5qvdnxijc', http_code: 404 }
Please sign in to leave a comment.
Comments
2 comments