Загрузка и сохранение файлов на сервере Blazor - PullRequest
1 голос
/ 03 октября 2019

Как загрузить и сохранить файл в базе данных, используя HttpPostedFileBase в Blazor

    [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");
    }

...