如何更改 Active Storage Service url_expires_in 超时? [英] How do you change the Active Storage Service url_expires_in timeout?

查看:25
本文介绍了如何更改 Active Storage Service url_expires_in 超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 Active Storage 创建签名变体 URL 时,它会将默认超时设置为 5.minutes.我真的很想增加这个,但我一直在搜索 Github 问题、代码潜水,但在任何地方都找不到.在服务类的第 44 行设置了 class_attribute,但是如何覆盖?

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

我正在使用 url_for 生成签名的变体链接,然后似乎没有办法更改设置.任何帮助将不胜感激.

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.

谢谢!:)

推荐答案

直接设置 ActiveStorage::Service.url_expires_in,例如在初始化程序中:

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 将添加 config.active_storage.service_urls_expire_in:

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

这篇关于如何更改 Active Storage Service url_expires_in 超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆