Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 477
perozzo Avatar asked Feb 26 '18 19:02

perozzo


2 Answers

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

like image 97
spender Avatar answered Oct 04 '22 22:10

spender


You should use 'Request.Body' instead of InputStream

like image 28
Kahbazi Avatar answered Oct 04 '22 20:10

Kahbazi