如何为通过 Active Storage 上传的 S3 文件设置缓存控制?

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

我想为通过 Active Storage 上传到 S3 的文件设置缓存控制。

rails 仓库中有这一行 (link here) :

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

所以我知道如果 **upload_options 中有 :cache_control 键,它就可以工作。 (link 到 aws 参考 here

如何在 upload_options 中正确设置某些内容?

storage.yml 中,添加一个 upload: 配置:

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