Streaming video from asp.net core web API to Android/iOS

Viewed 801

I'm facing an issue in my current Web API project. I have a database and one of the tables has a column of type varbinary. I would like to build an action method where I retrieve the data from that column and prepare it so when I call this action method, I can view the actual video from Android and iOS devices.

I managed to get it work on Android but not iOS, and my attempt for the Android is like the following:

[HttpGet]
public IActionResult Get() {
   var bytes = //getting the data form the database;
   var stream = new MemoryStream(bytes);
   return File(stream, "video/mp4");
}

I found answers and blog posts where they used PushStreamContent class and I think this class is not available in asp.net core.

1 Answers

Damn i'm trying to do the same but i'm having a lot of trubles. first of all you'll need to support partial content. asp.net core MVC updated to version 2.1.x (maybe also 2.0.x) have a new File method overload that return a FileStreamResult.

FileStreamResult File(Stream fileStream, String contentType, String fileDownloadName, Boolean enableRangeProcessing);

This should be your starting point. After this i wasn't still able to play videos on my iOS i've noticed that in the response header content-disposition: attachment; ... i'm investigating if removing the attachment token or sobstituting it with inline could do the trick

That's it! you just need that.

In my case it was HyperV external virtual switch that for some reason was limiting the connection speed to 20KiB/s and the videos where unable to play.

Related