Mvc: 406 Not Acceptable [Content type: video/mp4]

Created on 30 Nov 2016  路  4Comments  路  Source: aspnet/Mvc

Hello,
I've got a little problem. I can't get my service to stop converting everything to application/json

I tried:

services.AddMvc(config => {config.RespectBrowserAcceptHeader = true;});

i was even trying with [Produces("video/mp4")] but it says " doesnt have output formatter "

Still nothing result:
application/json
or
406 Not Acceptable

How to make it work in .net core 1.0 ?

Most helpful comment

Hmm, so is there any output formatters implemented by asp.net core to handle "video/mp4"

No.

Here's the equivalent in MVC Core 1.0:

C# [HttpGet] public IActionResult Get() { string videoPath = @"D:\sample.mp4"; if (System.IO.File.Exists(videoPath)) { return PhysicalFile(videoPath, "video/mp4", "sample.mp4"); } return StatusCode(StatusCodes.Status500InternalServerError); }

All 4 comments

We're going to need more information about what you're trying to do, including some code from your controller/actions.

If you returns a non-IActionResult from an action method, it gets run through the output formatters to try and write it to the response. By default we have the JSON formatter configured.

Hmm, so is there any output formatters implemented by asp.net core to handle "video/mp4"

This is my controller

        [HttpGet]
        [Produces("video/mp4")]
        public HttpResponseMessage Get()
        {
            string videoPath = @"D:\sample.mp4";
            if (System.IO.File.Exists(videoPath))
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StreamContent(new FileStream(videoPath, FileMode.Open, FileAccess.Read));
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("video/mp4");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = "sample.mp4"
                };
                return response;
            }
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
        }

It's working very good when i use simply owinservice

Hmm, so is there any output formatters implemented by asp.net core to handle "video/mp4"

No.

Here's the equivalent in MVC Core 1.0:

C# [HttpGet] public IActionResult Get() { string videoPath = @"D:\sample.mp4"; if (System.IO.File.Exists(videoPath)) { return PhysicalFile(videoPath, "video/mp4", "sample.mp4"); } return StatusCode(StatusCodes.Status500InternalServerError); }

Done :dagger: Thanks :)

Was this page helpful?
0 / 5 - 0 ratings