Rails ActiveStorage: how to get Variant url when in proxy mode?

Viewed 213

In /config/application.rb I have config.active_storage.resolve_model_to_route = :rails_storage_proxy.

I'm then generating the url with Rails.application.routes.url_helpers.rails_representation_url(img, only_path: true)

But I'm still getting the images served through a redirect instead of directly from my rails app like I would expect when I configured proxy mode.

Should I use a different way of generating the url? Or did i configure proxy mode wrong?

1 Answers

To get the variant URL when in proxy mode, you need to use the method Rails.application.routes.url_helpers.rails_storage_proxy_url(img, only_path: true)

Aditionally, when using api only mode, you need to enable the Flash middleware by adding config.middleware.use ActionDispatch::Flash to your application.rb. This is necessary because of this issue

Related