I am working on a .NET Core 2.2 web application. In one of my Controller methods, I perform editing tasks on a Word document and then send it back to the client. However, when I try to view the document on the client side, I encounter this dialog:
https://i.sstatic.net/NeNxR.png
I have attempted different approaches to solve this issue. Below is a snippet of the controller method (some earlier attempts are commented out!)
byte[] byteArray = System.IO.File.ReadAllBytes(compositeFileName);
//MemoryStream content;
//content = new MemoryStream(byteArray);
//string contentType = "application/octet-stream";
//return File(content, contentType, compositeFileName);
//return File(byteArray, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", compositeFileName);
return new FileContentResult(byteArray, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
Here's the JavaScript code (from a vue.js file)
self.$http
.post('/MyController/MyMethod', myData, self.IENoCacheHeaders)
.then(function (response) {
var blob = new Blob([response.body], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' })
var link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = 'test.docx'
link.click()
After inspecting the contents of response.body, I found a significant amount of binary data. I have tried switching between MIME types such as application/vnd.openxmlformats-officedocument.wordprocessingml.document and application/octet-stream but with no success.
If anyone can provide insight into what might be causing this issue, please let me know. The file being streamed back to the browser (compositeFileName points to a .docx file on the server) appears to be fine on the server - the problem seems to occur during the streaming and processing on the client side.
Thank you
Edward