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?

More than 1 year has passed since last update.

Firebase Storage の CORS エラー回避のメモ

Posted at

結論

下記の「CORSの構成」を読めばOK

公式からほぼ抜粋

まず gsutil をインストールします。すでに入っているなら、最新版にアップデートします。

必要に応じて、認証処理をします。init 済みなのに、認証が失敗するときは、re-initialize します。

$ gcloud ini

cors.json を作成します。

cors.json
[
  {
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  }
]

さらっと、公式では全部の origin に対して通るようにしてもいいんじゃ的なことが書いてあるんですけど、さすがに全部OKとか嫌な場合は下記のようにします。

cors.json
[
  {
    "origin": [
            "https://your-project-name.web.app",
            "https://your-other-domain..com"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  }
]

origin なので、サイト名だけでなく https:// とか http:// とか、ポート番号とかも(あるなら)記述が必要です。

作成したら、下記を実施します。

$  gsutil cors set cors.json gs://your-project-name.appspot.com

gs:// 以下のバケットの名前が分からないときは、Firebase のコンソールにいって Storage のところを見ると書いてあります。

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?