首页 > 解决方案 > 文件上传并保存在 Blazor 服务器端

问题描述

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

标签: fileblazorblazor-server-side

解决方案


推荐阅读