Why does it download an empty file using React?

Viewed 217

I have a question about react. I need to download a file from the uploads/doc folder. I've written my code, but it downloads an empty file. Could you give me a hint on how to fix this issue? Thank you so much!

if (result.isConfirmed) {
  //console.log("error while downloading document: ");
  await getDocfile(_id);
    fetch('http://localhost:4200/uploads/docs')
      .then(response => {
        response.blob().then(blob => {
          let url = window.URL.createObjectURL(blob);
          let a = document.createElement('a');
          a.href = url;
          a.download = document_name + '.pdf';
          a.click();
          
        });
    });
}
0 Answers
Related