public IActionResult Upload(IFormFile imageFile, string password) { Guid guid = Guid.NewGuid(); string uniqueFileName = $"{guid}-{imageFile.FileName}"; string fileNamePath = Path.Combine(_environment.WebRootPath, "Uploads", uniqueFileName); using var fileStream = new FileStream(fileNamePath, FileMode.CreateNew); imageFile.CopyTo(fileStream); DbManager db = new DbManager(_connectionString); int id = db.AddImage(fileNamePath, password); ShareImageVM vm = new ShareImageVM { Image = db.GetImage(id) }; return(View(vm)); }
public ActionResult Upload(string password, HttpPostedFileBase image) { string fileName = $"{Guid.NewGuid()}{Path.GetExtension(image.FileName)}"; string fullPath = $"{Server.MapPath("/UploadedImages")}\\{fileName}"; image.SaveAs(fullPath); DbManager mgr = new DbManager(Properties.Settings.Default.ConStr); int id = mgr.AddImage(new Image { FileName = fileName, Password = password, UserId = int.Parse(TempData["userId"].ToString()) }); UploadedViewModel vm = new UploadedViewModel { Id = id, Password = password }; return(View(vm)); }