LoginSignup
33
29

More than 5 years have passed since last update.

amazon S3画像へのクロスドメイン接続を許可する

Posted at

JavaScriptから非同期でs3の画像を取得するとき。
CORSという仕組みを使う。

S3でCORS設定

S3の設定ページで「CORS設定の編集」をクリック

qiita.png

AllowedHeaderを↓のような感じに編集。

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

もっと厳密に設定するなら↓が参考になりそう。
http://memocra.blogspot.jp/2012/09/s3cors.html

33
29
1

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
33
29