Reputation: 60
I have a post API method in my web API net core application thats has a Dto Class with the follow parameters:
public class ClassDto
{
public int Id { get; set; }
public Comunicacao Comunicacao { get; set; }
}
Comunicacao
Class:
public class Comunicacao
{
public int Id { get; set; }
public string Name { get; set; }
}
API Action(route has been setted correctly):
[HttpPost]
public async Task<IActionResult> Add([FromForm]ClassDto bannerDto, IFormFile imgDesktop)
{
try
{
if (ModelState.IsValid)
{
var result = await _banner.Add(classDto, imgDesktop);
return Ok(new { message = result.messageReturning, result.classDto });
}
else
{
return BadRequest(ModelState);
}
}
catch (Exception ex)
{
return BadRequest(ex.ToLogString(Environment.StackTrace));
}
}
So my question is, how can I send in Postman using FormData passing Comunicacao
Object Values? Because when I sent "Id", it works fine, but I can't find a way to send objects!
I cannot use FromBody
because as you all can see I'm sending a File as well.
Upvotes: 0
Views: 1266
Reputation: 1579
put the iformfile object inside your dto making it a single dto method then ur endpoint will look like public async Task Add([FromForm]ClassDto bannerDto) if you have put the iformfile outside cos of automapper then u can use [ignore] attribute over the property
sorry wanted to put this as comment for the previous answer but i am typing from mobile phone so ...meh
Upvotes: 1
Reputation: 1579
you can set body type to form-data and then in key value pair side just select file instead of text for your file upload
Upvotes: 0