Help us understand the problem. What is going on with this article?

AWS SDK for Rubyを使ってS3オブジェクトにCache-Controlヘッダを追加する

More than 5 years have passed since last update.

S3オブジェクトにCache-Controlヘッダを追加したいんだけど、AWS::S3::Object#metadataだとx-amz-metaってprefixが付いて困った。
解決策はObject#writeのオプションに指定すればよかった。
#move_toや#copy_toでも同じようにオプション指定ができる。

コードはざっくりこんな感じ

sample.rb
require "aws"
s3 = AWS::S3.new
bucket = s3.buckets["my-bucket"]
object = bucket.objects["obj-key"]

object.write(data, cache_control: "max-age=3600")

これだとデータのアップロードも走るんだけど、すでにS3に上がってるオブジェクトに対してCache-Controlだけ追加したいと思ったらどうするんだろ・・・。object.write(object.read, cache_control: "max-age=...") ・・・?まさかね。
今度調べてみよう。

追記
#copy_fromを使ってsourceに同一objectを指定することで、アップロードせずにCache-Controlを付けることが出来た

sample2.rb
require "aws"
s3 = AWS::S3.new
bucket = s3.buckets["my-bucket"]
object = bucket.objects["obj-key"]

object.copy_from(object, cache_control: "max-age=3600")
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした