1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AWS】S3にアプリの画像などを保管する方法ついて

Posted at

記事概要

Ruby on RailsにAWSのS3を使用し、アプリの画像などを保管する方法について、まとめる

前提

  • Macを使用している
  • Renderにデプロイしている
  • Ruby on Railsでアプリケーションを作成している
  • AWSのアカウントを保持している
  • S3を導入済みである

手順

  1. バケットの個別ページに遷移する
  2. 「アクセス許可」タブをクリックする
  3. パブリックアクセスのブロックを解除する
    Image from Gyazo
  4. バケットポリシーを以下のように変更、保存する
    {
        "Version": "2012-10-17",
        "Id": "Policy1544152951996",
        "Statement": [
            {
                "Sid": "Stmt1544152948221",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:GetObject",
                "Resource": "arn:aws:s3:::バケット名/*"
            }
        ]
    }
    
  5. バケットに画像をアップロードする
  6. その画像のオブジェクトURLをimgタグのsrc属性に指定する
    <img src="https://example.s3.ap-northeast-1.amazonaws.com/fork-knife.svg" alt="">
    
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?