I have an existing API, that is reading data from the request body:
[HttpPost]
public async Task<IActionResult> Post([FromBody] CreateVm vm)
{
if (!ModelState.IsValid) return BadRequest();
var result = await _service.CreateAsync(vm);
return Ok(result);
}
A new requirement came in, requesting that the client, wants to submit an image along with the view model. My first thought was to attach an IFormFile to the request, handle it in a different service and move on:
public async Task<IActionResult> Post([FromBody] CreateVm vm, IFormFile file) { /* ... */}
The result of this approach is, that I am getting a status code 415 "Unsupported Media Type" back.
Using postman I've tried setting the Content-Type to multipart/form-data, to no avail.
Is this approach somehow possible, or do I need to add a byte[] property to the viewmodel and parse the image from there?