Search code examples
ruby-on-railsrubyamazon-s3rails-activestorage

How to set a cache control for S3 files uploaded through Active Storage?


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?


Solution

  • in storage.yml, add an upload: config :

    amazon:
      service: S3
      upload:
        cache_control: 'private, max-age=31536000'