Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using .NNET Core 2.0 to develop my Web API in C# and I want to forward an MJEPG stream of images with HTTP GET request. I have created the multipart content but when I check the response I can only see the first image and no playing of video is happening. I have tried to even use an mjpeg external file that I know it works but it does the same thing, it display the first image.

What I have tried:

I tried using an already MJEPG stream that I receive from a Camera event and using mjepg file.

This is the Controller Get Request:
// GET: api/<controller>
[HttpGet]
public IActionResult Get()
{
   var path = Path.Combine(
                   Directory.GetCurrentDirectory(),
                   "LVUpload", "test.mjpeg");

    var stream = new FileStream(path, FileMode.Open);

    MultipartResult multipartResult = new MultipartResult
    {
        ContentType = "image/jpeg",
        Stream = stream
    };
    return multipartResult;
}

And the multipart implementation:
public class MultipartContent
{
    public string ContentType { get; set; }

    public Stream Stream { get; set; }
}

public class MultipartResult : MultipartContent, IActionResult
{
    private readonly System.Net.Http.MultipartContent content;

    public MultipartResult(string subtype = "x-mixed-replace", string boundary = "canonliveview")
    {
        if (boundary == null)
        {
            this.content = new System.Net.Http.MultipartContent(subtype);
        }
        else
        {
            this.content = new System.Net.Http.MultipartContent(subtype, boundary);
        }
    }

    public async Task ExecuteResultAsync(ActionContext context)
    {
            if (Stream != null)
            {
                var content = new StreamContent(Stream);

                if (ContentType != null)
                {
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ContentType);
                }

                this.content.Add(content);
            }

        context.HttpContext.Response.ContentLength = content.Headers.ContentLength;
        context.HttpContext.Response.ContentType = content.Headers.ContentType.ToString();

        await content.CopyToAsync(context.HttpContext.Response.Body);
    }

Can someone help on how can I do this with .Net Core 2.0? I know it's possible with full .Net framework but I have to use latest .Net Core.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900