Kalyani Shevale

Kalyani Shevale

  • NA
  • 3.2k
  • 711.6k

how to get image from andriod web service to server in mvc

Nov 12 2018 10:52 PM
I have created this code for getting an image from the Android side then this add-in folder then insert to database.
//Web Service 
  1. [HttpPost]
  2. public ActionResult UpdateUser(HttpPostedFileBase UploadLogo,string UserId)  
  3.       {  
  4.           if(UserId!=null && UploadLogo!=null)  
  5.           {  
  6.               #region  
  7.                var fileName = String.Empty;  
  8.                var file = string.Empty;  
  9.                if (UploadLogo != null)  
  10.               {  
  11.                  string strPath = Server.MapPath("/UserImage");  
  12.                   if (!System.IO.Directory.Exists(strPath))  
  13.                   { System.IO.Directory.CreateDirectory(strPath);}  
  14.                   //HttpPostedFileBase file1 = null;  
  15.                   UploadLogo = Request.Files[0];  
  16.                   fileName = Path.GetFileName(UploadLogo.FileName);  
  17.                   System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(strPath);  
  18.                   int count = dir.GetFiles().Length;  
  19.                   fileName = fileName.Substring(0, fileName.IndexOf('.')) + "_" + DateTime.Now.Millisecond + "-" + DateTime.Now.Second + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Hour + "." + fileName.Substring(fileName.IndexOf('.') + 1);  
  20.                   var path = Path.Combine(strPath, fileName);  
  21.                   UploadLogo.SaveAs(path);  
  22.                   file = fileName;  
  23.               }  
  24.               #endregion  
  25.               ViewModel.User.User user = new BussinessLogic.User.User(new UserRepository(new CRMContext())).EditUser(new ViewModel.User.User()  
  26.                   {  
  27.                       UploadLogo=file,  
  28.                       id=Convert.ToInt32(UserId)  
  29.                   });  
  30.                   if(user.ErrorMessage.Equals("Updated"))  
  31.                   {  
  32.                       return Json(new {message = "Image SuccessFully Updated" }, JsonRequestBehavior.AllowGet);  
  33.                   }  
  34.                   else  
  35.                   {  
  36.                       return Json(new { message = "Image Not Updated" }, JsonRequestBehavior.AllowGet);  
  37.                   }  
  38.           }  
  39.           else  
  40.           {  
  41.               return Json(new { message = "Please Select Image" }, JsonRequestBehavior.AllowGet);  
  42.           }  
  43.           
  44.       }  
 from android, image is get in string format .how to get this image then how to convert this image in image format.
 
 
 
from Andriod side image string:
"
iVBORw0KGgoAAAANSUhEUgAAAHMAAADMCAIAAADPvQsRAAAAA3NCSVQFBgUzC42AAAAgAElEQVR4
nNV9y6olubbdyHW0LlOwL+xtqlHVOwl2o8CdA/4Cf4b/wv/hf3TzunFwJlSBJiyRuDHfkmLtnfW6
1yJrV6wIhR5D861HfHp9JQCYAICGSFP/zwABDCaQ/ARA2PIvadpTufDy44IZAEgKtyLZXiRYvVYi
XdTEBOJysWaQWlAqukqcqo60/HySrCJ8ohey15hAPBkNDiLJn2sEeSrimloMCcBc8KI0Ljte0ef0
mGueZ/35WM+vkZ2gdlnIqfzLoiRz8x9oBIBa5KYJhTWBJU+4EIK0jNEIk6WVRrByE/rIC5/7aB1b
KW/hAHGUxgDxqfN1hCjfx47UE/7bKIIArnQQpTft/id6UeJHA89CQulNw2tvhBKj9XZtbnrUFux2
emSDcufF8mOnrCNYVxJg5x1HhytSR5bZX9nzALjJIwZ4AmCezCoBAZg0nJlsvXmVghzWZn+D1paG
8YmVGBOAw+rlEx3gzyUzWRe8WZU+iJrcZEolkNEHXUBzdXO5v7TNLz6RPxGacqZ2/eNPd5JEfXqW
pNaAmVG7IFi/TqxQVdyBPI/9z3RHIcQkf6m9VnzJE0/k+JHRb6UxzrPOuc74AqvSI1k2++fjMWsz
JumddVS2xsz8jDbRoSKrUuvCOKkjYGr592IzBKa8NYU3DN9VoM6G+U6m2ROF5h5e0WzYUrUNVckk
cXGwBz7eDVdZ+1sVJj7dLrd2eXrs4UFez3c0HgrNrpI06Xf/G7RcERAqVmnLRv7Y8oBayE0CQWUf
40CAhQ6clFiN65JzuXmk0Fy+q+WjyK/FsLUjDc97sGKVsytZmYUL1PsAoNgt42G28LGNcAP5Q0lo
s3goOMjZIoIzqboHkd6L9I74DsrYiXsv7dCpBiDIzctKFEeNeLqi11YSwGr/Xpa9NWfJwtUOVSA2
1nNY2a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