Hi rani,
Check this example. Now please take its reference and correct your code.
Namespaces
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Index(IFormFile postedFile)
{
using (var ms = new MemoryStream())
{
postedFile.CopyTo(ms);
var fileBytes = ms.ToArray();
ViewBag.Data = Convert.ToBase64String(fileBytes);
}
return View();
}
}
View
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<form asp-action="Index" asp-controller="Home" method="post" enctype="multipart/form-data">
<input type="file" name="postedFile" />
<input type="submit" value="Upload" />
@if (ViewBag.Data != null)
{
<hr />
<video controls autoplay height="300" width="300">
<source type="video/webm" src="data:video/webm;base64,@ViewBag.Data">
<source type="video/mp4" src="data:video/mp4;base64,@ViewBag.Data">
<source type="video/ogg" src="data:video/ogg;base64,@ViewBag.Data">
</video>
}
</form>
</body>
</html>
Screenshot