Download file (any kind) from Firebase Storage in web browser ReactJS

Viewed 310

I can't understand how the file download mechanism works. My problem is that it is missing the header CORS 'Access-Control-Allow-Origin'. I don't know where I have to put it. Is there a tutorial that explains how to use it? My code:

const downloadFile = filePathStorage => {
    storage.ref().child(filePathStorage).getDownloadURL()
    .then(url => {
        var xhr = new XMLHttpRequest();
        xhr.responseType = "blob";
        xhr.onload = function(event) {
            var blob = xhr.response;
        }
        xhr.open("GET", url);
        xhr.send();
    })
    .catch(err => {
        console.log("download file error: " + JSON.stringify(err))
        message.error("Se produjo un error. Por favor, vuelva a intentarlo.")
    })
}
0 Answers
Related