I am working on a client-server application, and at the moment i am returning a file result in my web api controller, like this:
FileContentResult result = new FileContentResult(System.IO.File.ReadAllBytes(docDestination), "application/msword")
{
FileDownloadName = "myFile.docx"
};
return result;
on my client side i receive the response like this:
i thaught at begin that the browser detects the file automaticly and fires the download dialog, but no, so i tried to treat the result as a blob like this:
.then(response => {
console.log("here lives the response:", response);
var headers = response.headers;
var blob = new Blob([response.bodyText], { type: headers['application/msword'] });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = "Filename";
link.click();
the download fires, but the content is not identified as docx file, and his content is broken.
Any tip on how to do it?
Thanks