如何在Blazor中使用HttpPostedFileBase
在数据库中上传和保存文件
[HttpPost]
public ActionResult Index(HttpPostedFileBase postedFile)
{
byte[] bytes;
using (BinaryReader br = new BinaryReader(postedFile.InputStream))
{
bytes = br.ReadBytes(postedFile.ContentLength);
}
FilesEntities entities = new FilesEntities();
entities.tblFiles.Add(new tblFile
{
Name = Path.GetFileName(postedFile.FileName),
ContentType = postedFile.ContentType,
Data = bytes
});
entities.SaveChanges();
return RedirectToAction("Index");
}