gregoryp
gregoryp

Reputation: 1019

Request.InputStream in ASP.NET Core

I'm trying to use this library in ASP.NET Core: https://github.com/infusion/jQuery-webcam to get the picture taken from a webcam.

In this example, MVC Capture webcam image, save file path of image to the database, this is what happen:

$(document).ready(function () {
                        $("#Camera").webcam({
                            width: 320,
                            height: 240,
                            mode: "save",
                            swffile: "@Url.Content("~/Scripts/jscam.swf")",
                            onTick: function () { },
                            onSave: function () {
                            },
                            onCapture: function () {
                                webcam.save("@Url.Action("Capture", "TrapActivity", new { id = @Model.Id , pid = @Model.PersonId})");
                            },
                            debug: function () { },
                            onLoad: function () { }
                        });
                   });

A Controller method called Capture is called from the View in this line: webcam.save("@Url.Action("Capture", "TrapActivity", new { id = @Model.Id , pid = @Model.PersonId})");

public ActionResult Capture(string ID)
    {
        var path = Server.MapPath("~/Images/ID_" + ID + ".jpg" );

        //var path1 = "~/Images/test.jpg;";



        var stream = Request.InputStream;
        string dump;

        using (var reader = new StreamReader(stream))
            dump = reader.ReadToEnd();


        if (System.IO.File.Exists(path))
        {
            System.IO.File.Delete(path);
            System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump));
        }
        else System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump));


        return View(ID);

    }

Inside it, there is a var stream = Request.InputStream;.

The problem is that in ASP.NET Core there is NOT a Request.InputStream.

What can I use instead?

Upvotes: 25

Views: 20557

Answers (2)

spender
spender

Reputation: 120400

Request.Body is the stream you're looking for.

Upvotes: 58

Kahbazi
Kahbazi

Reputation: 14995

You should use 'Request.Body' instead of InputStream

Upvotes: 5

Related Questions