I currently have a function in the backend that gives me a stream that contains the PDF file I'm trying to open a download dialog from the client side with this pdf attached.
What I couldn't be able to achieve till now is that I return the stream from the back end and from the front end client side I create this:
fetch(url)
.then((response) => {
return response.blob();
})
.then((blob) => {
var blob = new Blob([myFileStream], { type: 'application/pdf' });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName + '.pdf';
document.body.appendChild(link);
link.click();
});
This opens a download dialog and I could download the file. But, it gives me this error: Error Failed to load PDF document.
I know this might be duplicated but I tried some solutions that made me reach the state I'm at now.
What I'm sure of is that I have the correct PDF file as I can save it in the filesystem from the back end and open it manually and I can see the file content correctly.
What I'm not sure of is what is the correct response format that I should form my file into and return it back from the back end to the front end.