Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

ruby on rails - How do you change the Active Storage Service url_expires_in timeout?

When Active Storage creates a signed variant URL, it sets a default timeout of 5.minutes. I really want to increase this, but I've been trawling Github issues, code diving and cannot find it anywhere. On line 44 of the services class a class_attribute is set, but how can this be overwritten?

https://github.com/rails/rails/blob/5-2-stable/activestorage/lib/active_storage/service.rb#L44

I'm using url_for to generate the signed variant links and there doesn't seem to be anyway to change the setting then. Any help would be greatly appreciated.

Thank you! :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Set ActiveStorage::Service.url_expires_in directly, e.g. in an initializer:

# config/initializers/active_storage.rb
ActiveStorage::Service.url_expires_in = 1.hour

Rails 6 will add config.active_storage.service_urls_expire_in:

# config/initializers/active_storage.rb
Rails.application.config.active_storage.service_urls_expire_in = 1.hour

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...