Reputation: 3151
I'm trying to make a small upload file api by using ASP.NET Core 1.0. I have a model which I took from an MVC5 application:
public class RoomModel
{
public int Id { get; set; }
public string Name { get; set; }
public HttpPostedFileBase Image { get; set; }
}
I want to make a function like :
[HttpPost("upload")]
public IActionResult Upload(List<RoomModel> rooms)
{
// Check and upload file here.
// Save parameter to database.
}
In my MVC5, it is OK with HttpPostedFileBase , but in ASP.NET Core, I don't know how to archive with the same result.
Can anyone help me please ? Thank you.
P/S: I've searched for tutorials like this but found nothing. Every tutorial I've read is only about get key-value parameters , no tutorial is about placing information in a model like this .
Upvotes: 2
Views: 1575
Reputation: 3151
Finally, I've found this post :
http://www.mikesdotnetting.com/article/288/uploading-files-with-asp-net-core-1-0-mvc
From this post, my RoomModel will be like this :
public class RoomModel
{
public int Id { get; set; }
public string Name { get; set; }
public IFormFile Image { get; set; }
}
So, as my current knowledge, IFromFile replaces HttpPostedFileBase, and the step handling files is the same as HttpPostedFileBase.
Upvotes: 2