'Is there another way to view a PDF file from dotnet core API with react

I have dotnet core API thats returning a downloadable and i want my react to view as a blob but the pdf that is getting rendered is blank

Dotnet core code

           {
            ...
            var file = dbres.FilePath;

            // Response...
            System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
            {
                FileName = file,
                Inline = true // false = prompt the user for downloading;  true = browser to try to show the file inline
            };
            Response.Headers.Add("Content-Disposition", cd.ToString());
            Response.Headers.Add("X-Content-Type-Options", "nosniff");

            return File(System.IO.File.ReadAllBytes(file), "application/pdf");
         ...
          }

React code

  axios
  .get(
    `${process.env.REACT_APP_API_S_LINK}/home/viewattachment/${fid}`,
     headers: {Authorization: `Bearer ${Token}`,
     responseType: "blob"
  )

  .then(function (response) {
    if (response.status === 200) {
      //Create a Blob from the PDF Stream
      const file = new Blob([response.data], { type: "application/pdf" }); //Build a URL from the file
      const fileURL = URL.createObjectURL(file); //Open the URL on new Window
      window.open(fileURL);
    }
  })
  .catch((err) => {
    console.log({ err: err });
  });

The result: enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source