ASP.NET Core中的Request.InputStream

时间:2018-02-26 19:33:40

标签: c# asp.net asp.net-core

我试图在ASP.NET Core中使用此库:https://github.com/infusion/jQuery-webcam来获取从网络摄像头拍摄的照片。

在这个例子中,MVC Capture webcam image, save file path of image to the database,就是这样:

$(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 () { }
                        });
                   });

从此行的视图中调用名为Capture的Controller方法: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);

    }

在其中,有一个var stream = Request.InputStream;

问题是在ASP.NET Core中没有 Request.InputStream

我可以用什么代替?有人可以帮忙吗?

2 个答案:

答案 0 :(得分:16)

Request.Body是您正在寻找的信息流。

答案 1 :(得分:1)

你应该使用' Request.Body'而不是InputStream