Ross Ross - 1 year ago 162
C# Question

MVC4 FileResult PDF corruption

I am transmitting a PDF to an MVC controller, saving the PDF to a database, and retrieving it. If I save the PDF to disk on the server side (prior to returning a file result), it looks fine. However, when I do something akin to the following:

return File(fileBytesFromDB, "application/pdf", "file.pdf");

and try to view it from a browser (any browser), the PDF appears to be corrupt. In fact, it's an entirely different size.

What have I missed?

Answer Source

I found it. One of my coworkers had added in a tokenizer as a decorator of return actions, and it was tokenizing the file stream. I added some logic to ignore FileStreamResult and FileContentResult and now the PDFs come out okay.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download