Difference cl_image_path and cloudinary_url

RafJube
RafJube Member Posts: 2
edited October 2022 in Developer APIs

Hello,

I use Cloudinary in one App with Rails (and Active Storage).

I specified in folder to store the uploaded image in the config.storage.yml ().

I want to recover the images's url but I tried the 2 methods below, and the results are differents.

Method 1: Cloudinary::Utils.cloudinary_url(key) => result: http://res.cloudinary.com/dftgbltxx/image/upload/e17r587k5goey5syvfhcra8kwaoc

Method 2: cl_image_path(key) => result: http://res.cloudinary.com/dftgbltxx/image/upload/v1/Folder/e17r587k5goey5syvfhcra8kwaoc

Why?

Best Answer

  • Stephen
    Stephen Member, Cloudinary Staff Posts: 11
    Answer ✓

    If "key" there is from ActiveStorage, the second option is correct - that method is aware of the other ActiveStorage configuration, such as which folder the assets were uploaded to.

    The first method is general-purpose and the first parameter should be the asset's complete public_id value. If I understood correctly, the "key" is ActiveStorage's own reference for the file, and while the SDK does use that value when uploading to Cloudinary, that "key" value is only the last part of the public_id, so you should also include the folder path that was used by ActiveStorage if you're going to building URLs using other methods

Answers