2

I am working on a Web API project and I'm unable to post both model and file simultaneously at a time. Postman throws an exception:

System.Net.Http.UnsupportedMediaTypeException"

How can I fix this problem?

My code is looking like:

[HttpPost]
[Route("Appeal")]
public IHttpActionResult SaveAppeal(AppealModel model)
{
    try
    {
        var file = HttpContext.Current.Request.Files.Count > 0 ?
        HttpContext.Current.Request.Files[0] : null;

        var AppealResponses = _ContactService.SaveAppeals(model);
        return Ok(new { AppealResponses });
    }
    catch (Exception ex)
    {
        _log.ErrorFormat("Error in AppealResponses. Error:{0}", ex.Message);
        _log.Error(ex);
        throw;
    }
}
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Nimesh khatri
  • 723
  • 10
  • 26

2 Answers2

1

In Postman have you set the Content-Type header to application/json ?

Like this Content-Type: application/json That should solve it.

Som Bhattacharyya
  • 3,732
  • 31
  • 50
0

I have answered this before here with server side sample code.

Then in Postman, do a raw post and you can select your file and set your headers as needed.

Community
  • 1
  • 1
ManOVision
  • 1,833
  • 1
  • 12
  • 14