Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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! :)

like image 725
Paul Danelli Avatar asked Sep 29 '18 18:09

Paul Danelli


People also ask

What does active storage mean?

1 What is Active Storage? Active Storage facilitates uploading files to a cloud storage service like Amazon S3, Google Cloud Storage, or Microsoft Azure Storage and attaching those files to Active Record objects.

How do I add active storage in rails?

After creating a new application (or upgrading your application to Rails 5.2), run bin/rails active_storage:install to generate a migration that creates these tables. Use bin/rails db:migrate to run the migration. active_storage_attachments is a polymorphic join table that stores your model's class name.

What is active storage blob?

A blob is a record that contains the metadata about a file and a key for where that file resides on the service. Blobs can be created in two ways: Subsequent to the file being uploaded server-side to the service via create_after_upload!.


1 Answers

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
like image 142
George Claghorn Avatar answered Sep 22 '22 07:09

George Claghorn