Skip to content

Instantly share code, notes, and snippets.

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
string fileName = System.IO.Path.GetFileName(file.FileName);
string path = System.IO.Path.Combine(Server.MapPath("~/Images"), fileName );
if (IMAGE_FILE_TYPES.Contains(Path.GetExtension(file.FileName).ToUpperInvariant()) && file.ContentLength <= MAX_FILE_SIZE)
{
file.SaveAs(path);
string base64Image = Convert.ToBase64String(System.IO.File.ReadAllBytes(path));