ASP.NET Core MVC 中的 InputStream

far*_*izi 1 asp.net-core-mvc asp.net-core

考虑以下代码片段:

public ActionResult Upload(HttpPostedFileBase file)
{
        byte[] buffer= new byte[256];
        file.InputStream.Read(buffer, 0, 256);
        //...
}
Run Code Online (Sandbox Code Playgroud)

InputStream命令在 ASP.NET Core MVC 中不起作用。

?asp.net mvc core 中的 inputstream 不再支持,似乎有替代方案。我正在寻找 itlease 指导我

pfx*_*pfx 7

HttpPostedFileBase已被IFormFilein取代ASP.NET Core
请参阅有关文档ASP.NET Core 中文件上传

您的控制器操作方法应该接受一个IFormFile实例。

public ActionResult Upload (IFormFile file)
Run Code Online (Sandbox Code Playgroud)

IFormFile提供以下方法来访问其Stream.

public interface IFormFile
{
    Stream OpenReadStream();

    void CopyTo(Stream target);

    Task CopyToAsync(Stream target, CancellationToken cancellationToken = default);

    // Remaining members
}
Run Code Online (Sandbox Code Playgroud)