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

406 Not Acceptable [Content type: video/mp4] #5582

Closed
HelloMyDevWorld opened this issue Nov 30, 2016 · 4 comments
Closed

406 Not Acceptable [Content type: video/mp4] #5582

HelloMyDevWorld opened this issue Nov 30, 2016 · 4 comments

Comments

@HelloMyDevWorld
Copy link

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 ?

@rynowak
Copy link
Member

rynowak commented Nov 30, 2016

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.

@HelloMyDevWorld
Copy link
Author

HelloMyDevWorld commented Dec 1, 2016

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

@davidfowl
Copy link
Member

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:

[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);
}

@HelloMyDevWorld
Copy link
Author

HelloMyDevWorld commented Dec 2, 2016

Done 🗡️ Thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants