public ActionResult AsyncPictureUpload() { Stream stream = null; var fileName = ""; var contentType = ""; byte[] bin = null; if (String.IsNullOrEmpty(Request["qqfile"])) { // IE HttpPostedFileBase httpPostedFile = Request.Files[0]; if (httpPostedFile == null) { throw new ArgumentException("No file uploaded"); } stream = httpPostedFile.InputStream; fileName = Path.GetFileName(httpPostedFile.FileName); contentType = httpPostedFile.ContentType; } else { //Webkit, Mozilla stream = Request.InputStream; fileName = Request["qqfile"]; } var fileExtension = Path.GetExtension(fileName); if (!String.IsNullOrEmpty(fileExtension)) { fileExtension = fileExtension.ToLowerInvariant(); } if (String.IsNullOrEmpty(contentType)) { switch (fileExtension) { case ".bmp": contentType = "image/bmp"; break; case ".gif": contentType = "image/gif"; break; case ".jpeg": case ".jpg": case ".jpe": case ".jfif": case ".pjpeg": case ".pjp": contentType = "image/jpeg"; break; case ".png": contentType = "image/png"; break; case ".tiff": case ".tif": contentType = "image/tiff"; break; default: break; } } // Create Thumbnails var maxWidthSetting = _settingService.GetSettingByKey("MaxWidthAllowedForSmallThumbnails"); var maxHeightSetting = _settingService.GetSettingByKey("MaxHeightAllowedForSmallThumbnails"); var sliderImageWidth = maxWidthSetting.Value; var sliderImageHeight = maxHeightSetting.Value; // ReSharper disable once ComplexConditionExpression if (!string.IsNullOrEmpty(sliderImageWidth) && !string.IsNullOrEmpty(sliderImageHeight)) { int newWidth = Convert.ToInt32(sliderImageWidth); int newHeight = Convert.ToInt32(sliderImageHeight); stream = Request.InputStream; fileName = Request["qqfile"]; // Save File HttpPostedFileBase httpPostedFile = Request.Files[0]; if (httpPostedFile != null) { using (System.Drawing.Bitmap postedImage = new System.Drawing.Bitmap(httpPostedFile.InputStream)) { bin = _pictureService.scaleImage(postedImage, newWidth, newHeight, false); fileName = "data:image/jpeg;base64," + Convert.ToBase64String(bin); } } } int bytes = Request.Files[0].ContentLength; int Gbs = bytes / (1024 * 1024 * 1024); int temp = bytes % (1024 * 1024 * 1024); int MBs = temp / (1024 * 1024); temp = temp % (1024 * 1024); int kBs = temp / 1024; var picture = new EF.Core.Data.Picture() { PictureSrc = fileName, AlternateText = "", DisplayOrder = 0, IsActive = true, IsLogo = false, IsThumb = false, Url = fileName, IsOpenResource = false, Size = MBs, UserId = _userContext.CurrentUser.Id, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now }; _pictureService.Insert(picture); var bitMapImage = _pictureService.ConvertBase64IntoImage(picture.PictureSrc.Replace("data:image/jpeg;base64,", "")); var resizedImage = _pictureService.ResizeImage(bitMapImage, 100, 100); return(Json(new { success = true, PictureId = picture.Id, Picture = _pictureService.ImageToBase64String(resizedImage, System.Drawing.Imaging.ImageFormat.Jpeg), Default = false, DisplayOrder = "", StartDate = "", EndDate = "" }, "text/plain")); }