首页 > 解决方案 > Angular 2 问题的 CORS firebase 存储问题

问题描述

预期:访问 Firebase 存储桶时,在控制台日志中接收数据且没有错误。

会发生什么:类型的控制台日志中的错误Access to fetch from origin 'http://localhost:4004' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

标签: angularfirebasefirebase-storage

解决方案


  1. 云仪表板上单击“激活 Cloud Shell”按钮。 像这样
  2. 单击“打开编辑器”按钮。像这样
  3. 右键单击 1a,单击“新建文件”并将其命名为 cors.json 并添加以下内容。像这样

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

  1. 点击“打开终端”。像这样
  2. 粘贴以下内容

gsutil cors set cors.json YourBucketUrl


推荐阅读