Search code examples
javascriptc#asp.net-web-apibinaryfiles

Returns binary file and an other object with C# IHttpActionResult


I've learned how to returns binary files from C# Web Api here.

Now I want to do the same thing with a IHttpActionResult. I've found some answers here.

But what if I'd like to return an other object with the file ? I can return objects with Ok or Content functions but is it possible to do both at the same time ?

I got the idea of returning an object containing a C# byte array (resulting from File.ReadAllBytes) and create the Blob in JS from it. But the C# byte array becomes a string in JS and I have to convert it to a byte array again. Beyond the fact that it does not seems to be a very robust solution the codes I've found (here, here and here) to achieve this do not work for me.

Please help me, thanks.


Solution

  • Solution: use the http headers.