public ImageJSON Upload() { try { MultipartFormDataParser parser = new MultipartFormDataParser(HttpContext.Current.Request.InputStream); ImageJSON imageJson = new ImageJSON(); int uploadImageId = 0; // Single file access: FilePart file = parser.Files.First(); string filename = file.FileName; if (file != null && file.Data != null) { // Save the file to db Application.Services.Abstract.DTO.IImage image = new Application.Services.DTO.Image(); image.UserImage = parser.ReadFully(file.Data); uploadImageId = _imageService.UploadImage(image); imageJson.UploadedImageId = uploadImageId; } else { throw new WebException("The posted file was not recognised.", WebExceptionStatus.SendFailure); } return(imageJson); } catch (Exception ex) { _logger.Error(ex); throw ex; } }