public ActionResult Upload(Image image, int UserId, HttpPostedFileBase imageFile) { var fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}"; imageFile.SaveAs(Path.Combine(Server.MapPath("/UploadedImages"), fileName)); image.FileName = fileName; var db = new ImageDb(Properties.Settings.Default.ConStr); db.Add(image, UserId); return(View(image)); }
public ActionResult SubmitUpload(Image image, HttpPostedFileBase imageFile) { var db = new ImageDb(Properties.Settings.Default.ConStr); var user = db.GetByEmail(User.Identity.Name); image.UserId = user.Id; var fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}"; imageFile.SaveAs(Path.Combine(Server.MapPath("/UploadedImages"), fileName)); image.FileName = fileName; db.Add(image); return(View(image)); }
public ActionResult Upload(Image image, IFormFile imageFile) { var fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}"; string fullPath = Path.Combine(_environment.WebRootPath, "uploads", fileName); using (FileStream stream = new FileStream(fullPath, FileMode.CreateNew)) { imageFile.CopyTo(stream); } image.FileName = fileName; var db = new ImageDb(_connectionString); db.Add(image); return(View(image)); }