In your model, you need a property of type IFormFile
:
public class MyModel
{
public IFormFile Arquivo {get;set;}
}
In your object, or POCO class, you need a property of type byte[]
:
public class MyObject
{
public byte[] Foto {get;set;}
}
E In the action of your controller, you receive the Model, pass% pro_de% and then% pro_de% and then save it to the bank:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Upload(MyModel model)
{
if (ModelState.IsValid)
{
MyObject obj = new MyObject();
using (var memoryStream = new MemoryStream())
{
await model.Arquivo.CopyToAsync(memoryStream);
obj.Foto = memoryStream.ToArray();
}
await _context.MyObjects.AddAsync(obj);
_context.SaveChanges();
}
return View("Index");
}
Remember, in the form, add the property stream
I hope I have helped.