ActiveStorage: use public url?

mccollek
mccollek Member Posts: 3
edited December 2023 in Developer APIs

I'm using Cloudinary as an ActiveStorage store for ActionText in Rails 6.1, cloudinary gem v1.28. Instead of the local signed URL I'd like to have it use the direct URL to Cloudinary. In the ActiveStorage documentation, there is the concept of setting a public flag in storage.yml:

cloudinary:
  service: Cloudinary
  public: true

but I'm still receiving the 'localhost' link in dev. Does the Cloudinary gem allow for that configuration?

Tagged:

Answers

  • aleksandar
    aleksandar Member, Cloudinary Staff Posts: 14

    Hi @mccollek,

    Could you please confirm what method you're calling to generate the URL which is pointing to localhost (e.g. url_for helper or Blob#url / #Blob#service_url)?

    By default, assets uploaded to Cloudinary will be public (type: upload) unless you set a different type and/or use other features to restrict access, such as Access Control.

    Blob#service_url now Blob#url in Rails 6.1+ would give you the direct URL to the asset on Cloudinary. If the asset requires authentication (e.g. Signed URL or Token for Access Control) then you'll want to use the dedicated methods via the Cloudinary SDK such as cloudinary_url / cl_image_tag) which support generating those.