Search code examples
ruby-on-railsrubyrails-activestorage

Direct link (no redirect) to files in ActiveStorage


Using url_for() on a file stored in active storage returns a url that leads to the application and then redirects to the actual location. Because of a bug in firefox with CORS, the redirect breaks my application.

Is there any way to get the direct link to the file with ActiveStorage?


Solution

  • You can do this

    record.active_storage_object.blob.service.url

    Found here https://github.com/rails/rails/blob/main/activestorage/app/models/active_storage/blob.rb#L213