public FileContentResult GetImage(int id, int tamano) { using (var db = new Entities()) { Imagen img = new Imagen(); EE_IMAGENES staffvar = db.EE_IMAGENES.FirstOrDefault(p => p.ID_IMAGEN == id); if (staffvar != null) { if (staffvar.EXTENSION != "application/pdf") { using (var input = new MemoryStream(staffvar.IMAGEN_T_REAL)) using (var output = new MemoryStream()) { img.ResizeImage(input, output, tamano, tamano); return(File(output.ToArray(), staffvar.EXTENSION)); } } else { return(null); } } else { return(null); } } }
public ActionResult Upload(EE_IMAGENES imagenes, int ID) { var context = new Entities(); int idusuario = Convert.ToInt32(Session["ID_USR"]); HttpPostedFileBase postedFile = Request.Files["IMAGEN"]; byte[] tempImage; JsonResult objResult = null; Imagen img = new Imagen(); if (postedFile != null) { if (img.EsArchivoValido(postedFile)) { var fileName = Path.GetFileName(postedFile.FileName); // var path = Path.Combine(Server.MapPath("~/App_Data/"), fileName); tempImage = new byte[postedFile.ContentLength]; imagenes.IMAGEN_T_REAL = new byte[postedFile.ContentLength]; imagenes.EXTENSION = postedFile.ContentType; imagenes.TAMANO = postedFile.ContentLength; postedFile.InputStream.Read(tempImage, 0, postedFile.ContentLength); var v_resp = new ObjectParameter("p_res", typeof(Int32)); var result = context.P_EE_SECUENCIA("IMG", v_resp); var data = v_resp.Value.ToString(); imagenes.ID_TABLA = ID; imagenes.NOMBRE_IMG = postedFile.FileName; imagenes.ID_IMAGEN = Convert.ToInt32(data);; imagenes.IMAGEN_T_REAL = tempImage; imagenes.FECHA_REG = DateTime.Now; //aun no cuenta con login y usuario imagenes.ID_USR = 0; //postedFile.SaveAs(path); context.EE_IMAGENES.AddObject(imagenes); context.SaveChanges(); //context.p_EE_g var v_resp1 = new ObjectParameter("p_res", typeof(Int32)); var data1 = context.P_EE_ACTUALIZAR_IMAGEN(imagenes.TABLA, ID, Convert.ToInt32(data), v_resp1); var data2 = v_resp1.Value.ToString(); objResult = new JsonResult() { ContentType = "text/html", Data = new { success = true, result = "Se guardo la Imegen o Archivo Con Exito" } }; } else { objResult = new JsonResult() { ContentType = "text/html", Data = new { success = true, result = "El Archivo No es Valido" } }; } } else { objResult = new JsonResult() { ContentType = "text/html", Data = new { success = false, error = "Ocurrio un Error" } }; } return(objResult); }