Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternative of Httpcontext.Current.Request.Files in Asp.Net Core 2.0?

I referred this, which suggests that I can use IHttpContextAccessor to access HttpContext.Current. But I want to specifically receive files which that object doesn't seem to have.

So is there any alternative for Httpcontext.Current.Request.Files in Asp.Net Core 2.0

like image 869
Karan Desai Avatar asked Nov 01 '17 07:11

Karan Desai


1 Answers

Inside controller context and in action you can access files via HttpContext.Request.Form.Files:

public IActionResult Index()
{
    var files = HttpContext.Request.Form.Files;

    return View();
}

and outside controller you have to inject IHttpContextAccessor.

for upload file read File uploads in ASP.NET Core.

like image 70
Mohsen Esmailpour Avatar answered Sep 22 '22 13:09

Mohsen Esmailpour