尝试获取 JSON 文件时 Firebase CORS 错误

问题描述 投票:0回答:1

我目前正在开发一个 Web 应用程序,需要从 Firebase 存储中获取数据。但是,我在尝试访问资源时遇到了 CORS(跨域资源共享)问题。这是我收到的错误消息:

任何关于如何解决此 CORS 问题的见解或建议将不胜感激!谢谢你。

if (user) {
    const filePath = `users/${user.uid}/circuits/circuit.json`;
  
    const storageRef = firebase.storage().ref(filePath);
  
    storageRef.getDownloadURL()
      .then((url) => {
        console.log(url); // logs the URL
        fileManager.loadFile(url); // when I try to load the file I get the CORS error
      })
      .catch((error) => {
        console.error('Error getting download URL:', error);
      });
  } else {
    console.error('User is not authenticated.');
  }

我尝试将请求模式设置为“no-cors”,但它没有解决问题,我相信这不是推荐的解决方案。

javascript firebase cors google-cloud-storage firebase-storage
1个回答
0
投票

当您尝试从未列入白名单的客户端域从云存储桶下载资源时,会发生 CORS 错误。

要将域列入白名单,您可以使用 gsutil cli 命令。

请参阅文档。

© www.soinside.com 2019 - 2024. All rights reserved.