0

I have been struggling to download a file from Firestore storage lately using react Js to no avail. I keep getting 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.Here is my code and any assistance will be greatly appreciated as I do not know where I am going wrong.

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);
          });
    }
    
  }

I am very new to Firebase.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Nges Brian
  • 479
  • 1
  • 8
  • 22

1 Answers1

0

You need to adjust the ACLs of the storage. I found this stackoverflow post about this:

Firebase Storage and Access-Control-Allow-Origin

Nina
  • 38
  • 5