-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Serving media with byte ranges #3702
Comments
@Tratcher can you confirm that byte ranges are supported by the static file middleware? For media scenarios is the support in static file middleware sufficient? We had byte range support in Web API, but we haven't added it to MVC 6. |
Yes, range requests are automatically supported in the static file middleware. Note that it only supports one range at a time. I assume you're requesting this for the FileResult type? https://github.com/aspnet/Mvc/blob/31e42ee31286fe115c75336343a6cef68729f4d7/src/Microsoft.AspNet.Mvc.Core/FileResult.cs |
It's mainly to serve videos in MVC. The MVC 6 Response.Headers doesn't have a .Range property. Is there a way to do it in MVC so I could have something like: public ??? GetFile(string name) Not sure what type to return in Mvc6 or how to get the Range from the Request |
Oh and it also needs to run in dnx50 and dnx451 as I run it on a mono ARM platform too. |
@angelsix Why are you having MVC serve the file rather than having StaticFiles do it? |
I'm unsure how to use StaticFiles in any functional way. I thought it just served files directly based on direct URL names. How could I use StaticFiles to serve a file say at /media/somefolder/movie.mp4 from http://localhost/get/mymovie ? |
Ah, so there is some indirection going on. I think FileStreamResult or FileContentResult is what you're looking for, they just don't have range support yet. |
Ok. Any plans for it any time soon or any way to implement it manually? |
@danroth27 with have to comment on plans. To do it manually you can include the Microsoft.AspNet.Http.Extensions package and use httpContext.Request.GetTypedHeaders().Range to read the requested range. If it's a small range you can read it into a byte[] and use FileContentResult. If it's a wildcard range (30-*) you can Seek in the stream and use then FileStreamResult to send the remainder. If it's a large fixed range (0-1000000), then you need a custom stream or copy operation to stop in the right place. |
Just FYI...Web API 2 had support for byte ranges. As a workaround you could take a look at the following to come up with a solution: |
Moving to backlog, no plans to implement this for the current version. |
Is adding byte range support for filestreamresult\filecontent on the radar, now that 1.0 has been released? |
@muqeet-khan not currently committed, but we'll certainly consider it! |
How do we go about serving files in MVC 6 with byte range request support too (for serving videos for example so the requester can drag and load a video back and forward at any point)?
The text was updated successfully, but these errors were encountered: