public ActionResult Estimate(HttpPostedFileBase file) { try { // Giving new name and saving to disk string filePath = Guid.NewGuid() + Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/images/uploads"), filePath)); // Server path for processing string imagePath = Path.Combine(Server.MapPath("~/images/uploads"), filePath); // Resource path for HTML string sourcePath = "/images/uploads/" + filePath; // This line calls the fuctions that knows how to estimate and which estimator use EstimatorModelsController estimatorModelsController = new EstimatorModelsController(); string result = estimatorModelsController.Estimate(imagePath); // Converting age float age = float.Parse(result, System.Globalization.CultureInfo.InvariantCulture.NumberFormat); // Create new entry Estimation estimation = new Estimation { EstimationID = Guid.NewGuid(), Gender = Gender.female, Image = sourcePath, EstimatedAge = age, IPAddress = Request.UserHostAddress, DateTime = DateTime.Now }; // Save entry db.Estimations.Add(estimation); db.SaveChanges(); // Returning JSON return(Json(new { success = true, response = "File uploaded", image = sourcePath, estimation = age })); } catch (Exception exception) { return(Json(new { success = false, response = exception.Message })); } }
public ActionResult Estimate(HttpPostedFileBase file) { try { // Giving new name and saving to disk string filePath = Guid.NewGuid() + Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/images/uploads"), filePath)); // Server path for processing string imagePath = Path.Combine(Server.MapPath("~/images/uploads"), filePath); // Resource path for HTML string sourcePath = "/images/uploads/" + filePath; // ACÁ SE PREPROCESA LA BOMBA Y SE AGARRA EL LINK DEL BICHILLO // This line calls the fuctions that knows how to estimate and which estimator use EstimatorModelsController estimatorModelsController = new EstimatorModelsController(); string result = estimatorModelsController.Estimate(imagePath); // Converting age float age = float.Parse(result, System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ViewBag.Age = (int)age; ViewBag.Image = sourcePath; ViewBag.Pre = sourcePath; // Returning JSON return(Json(new { success = true, response = "File uploaded", image = sourcePath, preprocess = sourcePath, estimation = age })); } catch (Exception exception) { return(Json(new { success = false, response = exception.Message })); } }