I am sending to c# api. One of the functions isn't sent to the api. can you advise what is the reason. (other functions with this api work well).
component.
this.loggedUser.aValidateUser(this.newlyRegistered.uMobile).subscribe(res => {
alert("personal details were saved successfully"),
this.active = 2;
}, err => {
alert("There were wrong details. Please make the necessary changes");
}
);
}
service in angular:
aValidateUser(phoneNumber:string) {
return this.HTTP.post('http://localhost:54058/user/ValidateUser', phoneNumber ,this.httpOptions);
}
c# api:
[EnableCors("*", "*", "*")]
[RoutePrefix("user")]
public class UserController : ApiController
{
SenderLogic user = new SenderLogic();
[HttpPost]
[Route("UploadFile")]
public void UploadFile()//Saves passport in local folder
{
for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
{
var file = HttpContext.Current.Request.Files[i];
if (file != null && file.ContentLength > 0)
{
var fileName = DateTime.Now.ToString("yyyyMMdd_hhmmss") + Path.GetFileName(file.FileName);
var path = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), fileName);
file.SaveAs(path);
}
}
}
[Route("ValidateUser")]
[HttpPost]
public bool ValidateUser(string phoneNumber)//check if phone number-(identifier of user) exists
{
if (user.ValidateUser(phoneNumber) == true)
return true;
return false;
}
Debugging showed that the service doesn't send to c# api. while other functions with same api and function type work well.
EDIT function that does work: Angular-
if (files.length === 0) {
return;
}
let filesToUpload : File[] = files;
const formData = new FormData();
Array.from(filesToUpload).map((file, index) => {
return formData.append('file'+index, file, file.name);
});
this.clientHttp.post('http://localhost:54058/user/UploadFile', formData, {reportProgress: true, observe: 'events'})
.subscribe(event => {
if (event.type === HttpEventType.UploadProgress)
this.progress = Math.round(100 * event.loaded / event.total);
else if (event.type === HttpEventType.Response) {
this.message = 'Upload success.';
}
});
}
c# api:
[HttpPost]
[Route("UploadFile")]
public void UploadFile()//Saves passport in local folder
{
for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
{
var file = HttpContext.Current.Request.Files[i];
if (file != null && file.ContentLength > 0)
{
var fileName = DateTime.Now.ToString("yyyyMMdd_hhmmss") +
Path.GetFileName(file.FileName);
var path =
Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"),
fileName);
file.SaveAs(path);
}
}
}