Aashish Tyagi

Aashish Tyagi

  • NA
  • 26
  • 2.5k

getting null when send image in angular6 to mvc API

Nov 24 2018 2:30 PM
i am getting null when send image in angular6 to mvc API (formdata)
 
angular6 code function:-
 
AddUserProfilePic(){
let userID: string = localStorage.getItem("UserID");
const frmData = new FormData();
frmData.append('file', this.uploadedImage);
frmData.append('loginID', userID);
this._userService.AddProfilePic(frmData)
.subscribe(
(responce) => {
if (responce)
alert("responce is" + responce);
});
}
AddProfilePic(formData:FormData) {
const httpOptions = {
headers: new Headers({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
})
};
return this._http.post(SessionService.userApiUrl + "UpdateProfilePic", formData,httpOptions)
.map(
res => res.json()
);
}
 
c# code
 
[Route("api/User/UpdateProfilePic")]
[HttpPost]
public IHttpActionResult UpdateProfilePic()
{
System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
return Ok(1);
}
 
hfc.Count value is 0
i am sending two key from client side but in server side we find 0