public HttpResponseMessage UploadJsonFile() { HttpResponseMessage response = new HttpResponseMessage(); var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; string fileName = Path.GetFileName(postedFile.FileName); string fileExtention = Path.GetExtension(fileName); int fileSize = postedFile.ContentLength; if (fileExtention.ToLower() == ".jpg" || fileExtention.ToLower() == ".bmp" || fileExtention.ToLower() == ".gif" || fileExtention.ToLower() == ".png") { Stream stream = postedFile.InputStream; BinaryReader binaryReader = new BinaryReader(stream); byte[] bytes = binaryReader.ReadBytes((int)stream.Length); testDB.spUpload(fileName, fileSize, bytes); } var filePath = HttpContext.Current.Server.MapPath("~/UploadFile/" + postedFile.FileName); postedFile.SaveAs(filePath); } } return(response); }