LoginSignup
1
0

More than 5 years have passed since last update.

アプリケーションからS3内の画像を移動させる時にアクセス権限を付与する

Last updated at Posted at 2017-12-20

とあるプロジェクトで、ユーザーの投稿を論理削除し後々復活させると、
復活させた画像のパブリックアクセスのオブジェクト読み取り権限が無くなっていたのでその対応。
rails4環境です。

結論から

オプションでaclを指定します。

使用例

s3 = Aws::S3::Resource.new

# 対象にする画像オブジェクトを取得
object = s3.bucket("バケット名").object("対象ファイルのパス")

# 付与するオプションを定義。今回の肝。
options = {acl: 'public-read'}

# 移動先の定義
location = "移動先のパス"

# aclオプションを付けて指定先にコピー
object.copy_to(location, options)

# 元の画像は削除
object.delete

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0