Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Serving media with byte ranges #3702

Closed
angelsix opened this issue Dec 7, 2015 · 13 comments
Closed

Serving media with byte ranges #3702

angelsix opened this issue Dec 7, 2015 · 13 comments

Comments

@angelsix
Copy link

angelsix commented Dec 7, 2015

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)?

@danroth27
Copy link
Member

@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.

@Tratcher
Copy link
Member

Tratcher commented Dec 9, 2015

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

@angelsix
Copy link
Author

angelsix commented Dec 9, 2015

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)
{
... FileStream based on input name, and range from headers...
}

Not sure what type to return in Mvc6 or how to get the Range from the Request

@angelsix
Copy link
Author

angelsix commented Dec 9, 2015

Oh and it also needs to run in dnx50 and dnx451 as I run it on a mono ARM platform too.

@Tratcher
Copy link
Member

Tratcher commented Dec 9, 2015

@angelsix Why are you having MVC serve the file rather than having StaticFiles do it?

@angelsix
Copy link
Author

angelsix commented Dec 9, 2015

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 ?

@Tratcher
Copy link
Member

Tratcher commented Dec 9, 2015

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.

@angelsix
Copy link
Author

angelsix commented Dec 9, 2015

Ok. Any plans for it any time soon or any way to implement it manually?
So FileStreamResult will return correctly as a stream so something requesting a 2GB video wont wait for the full 2GB to be returned and instead get streamed the content from start to finish?

@Tratcher
Copy link
Member

Tratcher commented Dec 9, 2015

@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.

@kichalla
Copy link
Member

kichalla commented Dec 9, 2015

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:
http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Net.Http.Formatting/Internal/ByteRangeStream.cs
http://blogs.msdn.com/b/webdev/archive/2012/11/23/asp-net-web-api-and-http-byte-range-support.aspx

@Eilon Eilon added this to the Backlog milestone Dec 15, 2015
@Eilon
Copy link
Member

Eilon commented Dec 15, 2015

Moving to backlog, no plans to implement this for the current version.

@muqeet-khan
Copy link

Is adding byte range support for filestreamresult\filecontent on the radar, now that 1.0 has been released?

@Eilon Eilon removed this from the Backlog milestone Dec 22, 2016
@Eilon
Copy link
Member

Eilon commented Dec 22, 2016

@muqeet-khan not currently committed, but we'll certainly consider it!

@Eilon Eilon added this to the 2.0.0 milestone Feb 2, 2017
jbagga added a commit to aspnet/StaticFiles that referenced this issue Apr 7, 2017
@jbagga jbagga modified the milestones: 2.0.0-preview2, 2.0.0-preview1 Apr 28, 2017
jbagga added a commit that referenced this issue May 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants