【问题标题】:How to set a cache control for S3 files uploaded through Active Storage?如何为通过 Active Storage 上传的 S3 文件设置缓存控制?
【发布时间】:2019-10-06 21:31:00
【问题描述】:

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

rails repo (link here) 中有这一行:

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

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

如何在upload_options中正确设置一些东西?

【问题讨论】:

    标签: ruby-on-rails ruby amazon-s3 rails-activestorage


    【解决方案1】:

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

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

    【讨论】:

    • 嗨@Nicolas Maloeurve,感谢您的回答,您能否分享一些指向文档的链接,我们可以在其中找到有关其他可用设置以及可以在 storage.yml 中设置的更多信息,将是非常有帮助,谢谢。
    • @opensource-developer 我记得我必须在 Rails 存储库中挖掘,并且没有很多关于此的文档
    • 感谢您的回复@Nicolas Maloeuvre,我看到了一个通过谷歌云平台更改设置并将缓存设置应用于存储桶的选项,但不确定是否有办法以编程方式进行操作跨度>
    • 我没有找到官方文档,但我找到了一篇描述此设置如何工作的帖子:bitcrowd.dev/caching-with-active-storage
    猜你喜欢
    • 2020-07-06
    • 2021-03-01
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 2014-08-18
    相关资源
    最近更新 更多