retrieve file async over webapi in .dotnet core
WebApi in .Netcore makes it really easy to retrieve / download file asynchronously.
There are 2 different ways to go about this (could be more) but here's my approach
Check out the following codes (a and b - ain't that much of a difference)
FileStreamResult is async operation. You will get read chunk by chunk, asynchronously and delivered to client.
What about ActionResult?
Tricky part would be (c) creating your custom ActionResult to read and send to client. A huge differences to note is that, traditionally we use HttpMessageResponse. But this introduce conversion challenges and with dotnet core, we gonna have a huge incompatibilities issues too.
But WebAPI approach to solve this is pretty easy. Take a look at code below :-
As you can see, instead of creating you HttpMessageResponse manually, you can just leverage on existing ones. :)