Search code examples
angularapimultipartform-data

Facing issues while passing form data to a .NET Core API from the Angular side


We are facing some issues on passing form data to a .NET Core API from Angular.

Also, we have passed headers, but we are still facing the same issues.

Here is an example:

let headers = new HttpHeaders({ 'Content-Type': 'multipart/form-data'});
let options = { headers: headers };

How can we fix it?

https://i.sstatic.net/iMkUJ.png


Solution

  • On the Angular side, create FormData using this way:

    const formData = new FormData;
    formData.append('file', file);
    formData.append('Id', 323);
    

    Add in a Service like this way:

     await this.http.post("URL", formData)