public ActionResult GetImage(JewelryMachinesImageURL item) { if (item == null) { return(null); } string path = Server.MapPath("/") + item.ImageURL; if (!System.IO.File.Exists(path)) { return(null); } byte[] imageByteData = System.IO.File.ReadAllBytes(path); return(File(imageByteData, "image")); }
public ActionResult SaveImages(IEnumerable <HttpPostedFileBase> files, Companies company, JewelryMachines jewelryMachine) { // The Name of the Upload component is "files" if (files != null) { int i = 1; foreach (var file in files) { // Some browsers send file names with full path. // We are only interested in the file name. var fileName = Path.GetFileName(file.FileName); var webPath = "DataImages/JewelryMachines/" + company.Id + "/JewelryMachine" + jewelryMachine.Id; var physicalPath = Server.MapPath("/") + webPath; if (!System.IO.Directory.Exists(physicalPath)) { System.IO.Directory.CreateDirectory(physicalPath); } // The files are not actually saved in this demo physicalPath = physicalPath + "/" + i + "." + file.FileName.Split('.')[1]; webPath = webPath + "/" + i + "." + file.FileName.Split('.')[1]; file.SaveAs(physicalPath); //physicalPath = physicalPath.Replace(" ", "%20"); JewelryMachinesImageURL imageURL = new JewelryMachinesImageURL(); imageURL.ImageURL = webPath; jewelryMachine.JewelryMachinesImageURL.Add(imageURL); i++; } } db.SaveChanges(); // Return an empty string to signify success return(Content("")); }