Angular and .net core project image update problem

Viewed 64

I would like to update the image in a project I am involved in later, but it gives the error you see in the image. What is the reason for this?

enter image description here

Error Code; error: "{\"errors\":{\"photo\":[\"Error converting value \\\"C:\\\\fakepath\\\\big___Page_88f2fa9e-18f1-472b-85b2-cf88d4f5c371big___Page_2b84e9ea-e78f-4ffe-ac76-8c2d3fe8030cmanset-kirmizi-700x350-px.png\\\" to type 'Microsoft.AspNetCore.Http.IFormFile'. Path 'photo', line 1, position 324.\"]},\"type\":\"https://tools.ietf.org/html/rfc7231#section-6.5.1\",\"title\":\"One or more validation errors occurred.\",\"status\":400,\"traceId\":\"0HMHNUCP6V4NR:0000000B\"}"

Backend Code;

if (request.Photo != null)
                {
                    var fileUpload = Core.Extensions.FileExtension.FileUpload(request.Photo, fileType: Core.Enums.FileType.Image);
                    if (fileUpload != null)
                    {
                        isThereAnyUser.Photo = fileUpload.GuidName;
                    }
                }
                _userRepository.Update(isThereAnyUser);

Api Code;

   public async Task<IActionResult> Update([FromBody] UpdateUserCommand updateUser)
        {
            var result = await Mediator.Send(updateUser);
            if (result.Success)
            {
                return Ok(result.Message);
            }

            return BadRequest(result.Message);
        }

Angular Code;

updateUser() {
    let userModel = Object.assign({}, this.userUpdateForm.value);
    if (this.userUpdateForm.valid) {
      this.userService.userUpdate(userModel).subscribe(data => {
        this.alertfyService.warning(data);
      })

Angular Html;

  <input type="file" id="file" accept=".jpg,.png,.gif" multiple  (change)="uploadFile($event)"  class="form-control"formControlName="photo">

    }
  }
  uploadFile(event: any) {
    this.imageFiles = event.target.files;
  }

Angular userUpdate Code;

 userUpdate(user:UserDto): Observable<any> {
    return this.httpClient.put(`https://localhost:6001/Admin/api/Users`,user,{ responseType: 'text' });
  }
0 Answers
Related