【问题标题】:Download Audio file from firebase storage using React JS使用 React JS 从 firebase 存储下载音频文件
【发布时间】: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


    【解决方案1】:

    您需要调整存储的 ACL。我发现这个关于这个的 stackoverflow 帖子:

    Firebase Storage and Access-Control-Allow-Origin

    【讨论】:

      猜你喜欢
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-24
      • 2023-04-01
      • 2021-04-16
      • 1970-01-01
      相关资源
      最近更新 更多