2 min read
Published on March 11, 2025
When serving files in a rails app, I came across two options:
Redirect URLs are generated using rails_storage_redirect_url
. They are signed URLs that point directly to the blob rather than going through the proxy controller. So for resources that will be viewed in other servers, it is better to use redirect URLs.
For example, if we want to export some data to Google docs, then we should use redirect URLs since they don't require going through our server.
Note that we can set an expiry on redirect URLs. This is set through config.active_storage.urls_expire_in
.
# Eg: config/environments/production.rb
config.active_storage.urls_expire_in = 10.seconds
Proxy URLs work best when the access to the resource is controlled through our server. For example, a download link. This means that you don't expose the service you use for storage.
Proxy URLs are generated using rails_storage_proxy_url
. There is no expiry for proxy URLs.
You can set either proxy or redirect as the default configuration in your rails app using the the config config.active_storage.resolve_model_to_route
.
It allows two values: :rails_storage_redirect
or :rails_storage_proxy
The default value is :rails_storage_redirect
# Eg: config/environments/production.rb
config.active_storage.resolve_model_to_route = :rails_storage_proxy