Search code examples
ruby-on-railsrails-activestorage

Rails Active Storage creating a direct download link


I'm using Active Storage with Rails 5.2.

When I create a download link for an image, it generates an URL for the blob that points to the rails application.

Is there any way to create a download link that directory points to a cloud service like S3 without redirecting to the rails application?


Solution

  • You can get the link of the file by using ActiveStorage service_url method like this:

    Model.last.attachment.service_url
    

    It will return the service link for your attachment. You can read more about service_url here