public IHttpActionResult UploadImage() { if (User.IsInRole("ADMIN")) { try { PortalUtility.CleanupTempFiles(); string imagelist = String.Empty; foreach (string file in HttpContext.Current.Request.Files) { HttpPostedFile fileContent = HttpContext.Current.Request.Files[file]; if (fileContent != null && fileContent.ContentLength > 0) { // get a stream string imagename = GetImageName(); string path_thumb = Path.Combine(HttpContext.Current.Server.MapPath(Models.RecipeImage.Path_TempThumbnail), imagename); string path_full = Path.Combine(HttpContext.Current.Server.MapPath(Models.RecipeImage.Path_TempStandard), imagename); Stream stream = fileContent.InputStream; Image img = Image.FromStream(stream); Image thumbimg = PortalUtility.ScaleImage(img, 100, 100); thumbimg.Save(path_thumb, System.Drawing.Imaging.ImageFormat.Png); Image regimg = PortalUtility.ScaleImage(img, 800, 600); regimg.Save(path_full, System.Drawing.Imaging.ImageFormat.Png); imagelist += imagename + ","; } } imagelist = imagelist.Trim(','); string[] returnval = imagelist.Split(','); return(Ok(returnval)); } catch (Exception ex) { PortalUtility.SendErrorEmail(ex); return(new PortalUtility.PlainTextResult("Upload failed: " + ex.Message, HttpStatusCode.InternalServerError)); } } else { return(new PortalUtility.PlainTextResult("Demo login does not allow image uploads.", HttpStatusCode.Unauthorized)); } }