Skip to main content

How can I generate a download/attachment URL for a private image?

Comments

4 comments

  • countify

    Is there something similar for authenticated assets ?

    0
  • Aleksandar Kostadinov

    Hi @countify,

    You can use the same method for "authenticated" type too. You would just need to pass the "type" parameter set to "authenticated" when calling the method. E.g. using Ruby SDK:

    Cloudinary::Utils.private_download_url('sample123', 'jpg', :type => "authenticated", :attachment => true)

    Please try this out and let me know how it goes.

    0
  • Fernando Gonzalez

    if I wanted to make a download button based on a cl_image_tag ?

    0
  • Aleksandar Kostadinov

    Hi Fernando,

    You could try the below (where you replace `sample` with the public_id of the asset you want to download:

    cl_image_tag("sample.jpg", :flags=>"attachment")

    That will return you a URL with the fl_attachment transformation that will download the asset on click instead of opening it inline.

    You can also set a custom name for the downloaded file per the structure below: 

    cl_image_tag("sample.jpg", :flags=>"attachment:my-custom-filename")

    You can also apply other transformations in the `cl_image_tag` method as described here (https://cloudinary.com/documentation/rails_image_manipulation#the_cl_image_tag_method).

    Please try this out and let me know if it works for you.

    0

Please sign in to leave a comment.