using System.Collections.Generic;
using System.Threading.Tasks;
namespace Vidly.Controllers
public class ImageController : Controller
ApplicationDbContext _context;
_context = new ApplicationDbContext();
public ActionResult Index()
public ActionResult Index(HttpPostedFileBase httpPostedFileBase)
if (httpPostedFileBase != null)
Picture picture = new Picture
image = ConvertToByte(httpPostedFileBase)
_context.Pictures.Add(picture);
public byte[] ConvertToByte(HttpPostedFileBase file)
BinaryReader rdr = new BinaryReader(file.InputStream);
imageByte = rdr.ReadBytes((int)file.ContentLength);
public async Task<ActionResult> RenderImage()
Picture item = await _context.Pictures.FindAsync(3);
byte[] photoBack = item.image;
string imreBase64Data = Convert.ToBase64String(photoBack);
string imgDataURL = string.Format("data:image/jpg;base64,{0}", imreBase64Data);
ViewBag.ImageData = imgDataURL;
return View("SingleImage");