file - 文件上传并保存在 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");
}
解决方案
推荐阅读
- c++ - 为什么这个for循环总是显示'o's.C++
- javascript - 单击链接时在单独的 div 中播放视频
- amazon-web-services - 从 Lambda 调用 AWS AppSync graphql API
- fortran - Fortan 中包含语句中的换行符
- python - Heroku Server Python Socket不接受客户端连接
- git - 特定存储库的 Git 全局配置?
- vue.js - 道具不更新?
- nginx - nginx 如何知道我从哪个站点重定向到我的站点?
- bash - sed 在 macOS 中带有评论,它给了我一个错误
- android - 无法更改 Basic Activity 模板第一个片段中的 TextView