【发布时间】:2021-03-06 11:28:19
【问题描述】:
我在google云存储中保存了一个json文件,我想获取文件,读取json内容并将内容保存到客户端indexeddb。
loadJSON(function(json) {
console.log(json); // this will log out the json object
});
var fileUrl ="https://firebasestorage.googleapis.com/v0/b/rwrwr-rwr.appspot.com/o/TestCatalog.json?alt=media&token=r545-54-54-54-45455"
function loadJSON() {
var request = new Request(fileUrl);
fetch(request, {mode: 'cors'}).then(function(response) {
// Convert to JSON
return response.json();
}).then(function(j) {
// Yay, `j` is a JavaScript object
console.log(JSON.stringify(j));
}).catch(function(error) {
console.log('Request failed', error)
});
}
提取产生此错误
CORS 策略已阻止来自原点“null”:请求的资源上不存在“Access-Control-Allow-Origin”标头。如果不透明的响应满足您的需求,请将请求的模式设置为“no-cors”以获取禁用 CORS 的资源。
如何获取 firebase 存储 json 文件?
【问题讨论】:
标签: javascript firebase firebase-storage