【发布时间】:2021-10-19 00:37:28
【问题描述】:
我最近一直在努力使用 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 的新手。
【问题讨论】:
标签: javascript reactjs download firebase-storage