I have running Angular 9 application and I wanted to implement File upload behavior. In the form, user has to enter title, description and upload only one file in .zip format and while clicking on Submit, I want to send the form values along with files to Backend (using dotnet) via http post call.
file-upload.component.ts
uploadFile(files) {
const formData = new FormData();
const fileToUpload = files[0] as File;
formData.append('file', fileToUpload, fileToUpload.name);
const data = {
title: this.form.value.Title,
description: this.form.value.Description,
File: formData
};
console.log(data);
this.http.post('https://localhost:5001/api/idea/add', data).subscribe((response) => {
console.log(response);
}});
}
file-upload.component.html
<input type="file" #file placeholder="Choose file" (change)="uploadFile(file.files)" multiple>
FileController.cs
[HttpPost("api/idea/add")]
public async Task<IActionResult> AddIdea([FromBody] IdeaDto ideaDto) { }
Backend expects the data to come in below format
IdeaDto.cs
public class IdeaDto
{
public IFormFile File { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
I am getting below error while submitting the data
Also, I did console.log(data) and got File value as shown in the below image. I am not sure whether this the correct data
What is wrong here? I'm really out of ideas, maybe I need a fresh thoughts on this after spending so much time

