How to generate derivatives URL with download_endpoint plugin

Hello, I can’t figure out how to generate derivative URLs with the derivative plugin, but via the download_endpoint plugin.

In normal circumstances, one would do:

MyModel.find(1).image.image_url ==

However with the derivative param on must use

MyModel.find(1).image.image_url(:thumb) ==

And with derivative + download_endpoint plugins:

MyModel.find(1).image.download_url ==

MyModel.find(1).image.download_url(:thumb) # not ok, no such param

Is it possible to generate such a URL ?

The #download_url method is defined on a Shrine::UploadedFile object. You can retrieve a Shrine::UploadedFile object representing a derivative by passing the name to the attachment method:

photo.image(:thumb) #=> #<Shrine::UploadedFile>

Then you call #download_url on that object:


Calling photo.image_url(:thumb) is just a shorthand for photo.image(:thumb).url.

Thanks @janko, it works great :wink:

Have a great day!

1 Like