Fig:Call a post man like this
Craete a API Controller And using this updateprofileImage method.
=======================================================
public HttpResponseMessage updateprofileImage()
{
Customer objCustomer = new Customer();
HttpResponseMessage response = new HttpResponseMessage();
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
// HttpPostedFile file = httpRequest.Files[0];
//string[] F_Name = file.FileName.Split('.');
//string mapName = F_Name[0] + "-" + "Cus" + objCustomer.CustomerId + "." + F_Name[1];
//string strCustomerfileOriginalPath = "~/Content/ProfilePicture";
//string filepath = httpRequest.MapPath(strCustomerfileOriginalPath);
//filepath = Path.Combine(filepath, System.IO.Path.GetFileName(mapName));
//file.SaveAs(filepath);
HttpPostedFile file = httpRequest.Files[0];
int UserId = 1;// CustomerId;//httpRequest["CustomerId"];
string strCustomerfileOriginalPath = string.Empty;
strCustomerfileOriginalPath = "~/Content/Uploads/Customer/ProfilePic";
string strTutorImg = string.Empty;
if (file != null)
{
string CustomerImage;
CustomerImage = DateTime.UtcNow.Ticks + "-" + 'C' + "-" + file.FileName;
var filepath = httpRequest.MapPath(strCustomerfileOriginalPath);
if (!Directory.Exists(filepath))
Directory.CreateDirectory(filepath);
filepath = Path.Combine(filepath,
System.IO.Path.GetFileName(CustomerImage));
file.SaveAs(filepath);
tblAssign.AttachedFile = strTutorImg;
objCustomer.OrgProfilePic = file.FileName;
objCustomer.MappedProfilePic = CustomerImage;
}
}
return Request.CreateResponse(HttpStatusCode.OK, objCustomer); ;
}
No comments:
Post a Comment