Let's say I have an ASP.NET WebAPI Controller that looks like that:
public class StuffController
{
[HttpGet]
[Route("api/v1/stuff/{id:int}")]
[ResponseType(typeof(Model))]
public async Task<IHttpActionResult> GetAsync(int id)
{
// ...
}
[HttpPut]
[Route("api/v1/stuff/{id:int}")]
[ResponseType(typeof(IHttpActionResult))]
public async Task<IHttpActionResult> UpdateAsync(int id, Model model)
{
// ...
}
[HttpPost]
[Route("api/v1/stuff")]
[ResponseType(typeof(IHttpActionResult))]
public async Task<IHttpActionResult> CreateAsync([FromBody] Model model)
{
// ...
}
}
Is there anyway I can send / upload / post from an Angular app (obviously in a service with HttpClient properly injected) a model (which is the json data that would be extracted from the body) and the form data containing files...)?
The problem is... I don't really see how:
const formData = new FormData();
const uploadReq = new HttpRequest('POST', url, formData, {
reportProgress: true,
headers: headers
});
It's like whether...:
- I add the json data as part of the form data and cannot have it extracted from body as "such" in the Web API Controller action, and I have to keep the key used in the Angular app for json data and then loop over the remaining keys (which are supposedly all files).
- I have to send a different "POST" for each file