LoginSignup
0
0

More than 5 years have passed since last update.

ブラウザからGCSからファイルをダウンロードしようとして、CORSエラーが出た場合の対応

Posted at

解決方法

ブラウザからGCSのファイルをDLする場合には、対象バケットにCORS設定を追加する必要がある。

やりかた

URLをorigin指定したjsonを記載した設定ファイルを作る。

cors-config.json
[
    {
      "origin": ["http://example.appspot.com"],
      "responseHeader": ["Content-Type"],
      "method": ["GET", "HEAD", "DELETE"],
      "maxAgeSeconds": 3600
    }
]

対象バケットに向けてgsutilコマンドを実行

gsutil cors set cors-config.json gs://example-bucket

以下コマンドでcors設定が確認できる

gsutil cors get gs://example-bucket

参考: https://cloud.google.com/storage/docs/configuring-cors

0
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
0
0