使用React JS从firebase存储下载音频文件



我最近一直在努力使用react Js从Firestore存储下载文件,但无济于事。我一直得到Access to XMLHttpRequest at 'https://firebasestorage.googleapis.com/filepath?alt=media&token=df649468-6042-4ce7-ab21-402242239c56' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.这是我的代码,任何帮助将非常感激,因为我不知道我在哪里出错。

const download = (url, filename)=> {
console.log('we are here to download', filename);
if(url && filename){

Axios.get(url, {
withCredentials: false,    
crossDomain:true,
headers: { 
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods':'GET,PUT,POST,DELETE,PATCH,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control'
},
responseType: 'blob',

}).then(res => {
fileDownload(res.data, filename);
});
}

}

我是Firebase的新手。

需要调整存储的acl。我在stackoverflow上找到了这个帖子:

Firebase Storage and Access-Control-Allow-Origin

最新更新