6

I want to set a cache-control to files uploaded to S3 through Active Storage.

There is this line in the rails repo (link here) :

object_for(key).put(body: io, content_md5: checksum, content_type: content_type, **upload_options)

So i know that if there is the :cache_control key in **upload_options it could work. (link to aws reference here)

How to properly set something in upload_options?

1 Answer 1

20

in storage.yml, add an upload: config :

amazon:
  service: S3
  upload:
    cache_control: 'private, max-age=31536000'
4
  • 2
    hi @Nicolas Maloeurve, thanks for the answer, can you also share some link to the documentation where we can find more information about what other settings are available and can be set in storage.yml, would be very helpful, Thanks. Jul 4, 2019 at 14:02
  • @opensource-developer I remember that I had to dig in the Rails repository, and that there is not a lot of documentation about this Jul 5, 2019 at 9:40
  • thanks for your reply @Nicolas Maloeuvre, i see an option to change the setting via google cloud platform and apply cache setting to bucket, but not sure, if there is a way to do it programmatically Jul 5, 2019 at 10:00
  • 2
    I did'n find the official documentation but I found a post that describes how this setting works: bitcrowd.dev/caching-with-active-storage Jul 11, 2020 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.