【问题标题】:How to fetch json file from google firebase storage如何从谷歌 Firebase 存储中获取 json 文件
【发布时间】:2020-11-23 22:11:06
【问题描述】:

背景 我需要将大型产品库存上传到客户端的 indexeddb,以便我可以执行一些离线操作。它们的 json 文件大小可能高达 50 MB。因此,我将 json 文件上传到 google firebase storage 以获取存储文件,读取 json 并将它们添加到 indexeddb。

问题

从谷歌存储中获取和读取文件的最佳方式是什么?

这是我的获取代码

var fileUrl ="https://firebasestorage.googleapis.com/v0/b/konstant-ccbcc.appspot.com/o/storeid.json?alt=media&token=8d56ba73-331e-452e-b0d4-e552264feee3"

function loadJSON() {

fetch(fileUrl)
  .then(function(resp){
    return resp.json()
  })
  .then(function(data){
    console.log(data)
  })

}

这是我遇到的错误

Fetch API 无法加载 CORS 请求的 URL 方案必须是“http”或“https”。 Uncaught (in promise) TypeError: Failed to fetch 在加载JSON

【问题讨论】:

  • 当我访问那个站点时,它返回{ "error": { "code": 404, "message": "Not Found. Could not access bucket test-ccbcc.appspot.com", "status": "ACCESS_BUCKET" } } 这是你想要的吗?我对此表示怀疑
  • @JonahG 我已经添加了实际的文件 url

标签: javascript firebase


【解决方案1】:

存储文件不可公开访问。 将具有查看者权限的allUsers 添加到文件权限或向请求添加身份验证。配置CORS,见Firebase Storage and Access-Control-Allow-Origin

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-03-06
  • 2021-08-30
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-16
  • 1970-01-01
相关资源
最近更新 更多