John Doe
John Doe

Reputation: 493

Upload a file trough an API

I don't find how to do it in the Core version of ASP.NET.

I have found this link: http://www.c-sharpcorner.com/article/uploading-image-to-server-using-web-api-2-0/

but every line is wrong in the Core version.

I got the current context:

var httpRequest = HttpContext.Request;

Upvotes: 0

Views: 71

Answers (1)

Ahmed Magdy
Ahmed Magdy

Reputation: 516

You can send it via form-data from any client-side and take it in the action like this

[HttpPost]
public IActionResult MyAction([FromForm] IFormFile file)
{

}

you will be able to access it from the parameter or you can user

Request.Form.Files

Upvotes: 2

Related Questions