Generating an attachment of a private image in Rails is done by calling the cl_private_download_url
view helper method, for example in Rails:
<%= link_to("Download", cl_private_download_url("my_private_image", :jpg, :attachment => true)) %>
Or by using Cloudinary::Utils.private_download_url from your model or controller, for example:
Cloudinary::Utils.private_download_url self.cloudinary_id, self.format, attachment: true
Note that this also works for authenticated images as well, by passing the type
parameter and setting it to authenticated
:
Cloudinary::Utils.private_download_url('sample123', 'jpg', :type => "authenticated", :attachment => true)
To see code examples in other languages or to find additional information on providing temporary access to private assets, please refer to our media access documentation.
Comments
4 comments
Is there something similar for authenticated assets ?
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:
Please try this out and let me know how it goes.
if I wanted to make a download button based on a cl_image_tag ?
Hi Fernando,
You could try the below (where you replace `sample` with the public_id of the asset you want to download:
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:
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.
Please sign in to leave a comment.