adding transformations to existing cloudinary URL...
when I upload an image to cloudinary, I save the URL to my database like this:
https://res.cloudinary.com/ctbuh2/image/upload/v1601072201/autodesk_wqqkm8.jpg
but then if I want to create a variation of that image (resized, for example), I have to somehow modify that URL to include 'w_200` right before the '/v160../' part.
Not very easy, but I have a helper method that can parse existing transformation options inside any cloudinary url (if any), and modifies them right on the fly.
But I was wondering if there was an easier way to do this.
I found cloudinary_url method:

but that just returns back the same URL without any modifications that I would expect...
now of course the obvious solution would be to save other pieces of data from the upload response, like public_id and version_id, and use those to easily construct any transformation URL that I want at anytime.
But is this the only way or even the best way? How do people typically store references cloudinary assets?
-
Hi Paul,
The recommended way of handling your database would be as you mentioned at the end of your post - saving the 'public_id', 'version', and any other attribute you need, separately.
Cloudinary SDKs' helper methods, such as cloudinary_url are accepting the public_id as the image identifier, and using the entire image URL is not recommended.1
Post is closed for comments.
Comments
1 comment