415 Unsupported Media Type asp.net core

Malik Kashmiri picture Malik Kashmiri · Mar 12, 2018 · Viewed 19.7k times · Source

Detail

I am trying to post a file from Postman to the endpoint I have created. but it gives me this error. I am not passing the header Content-Type in postman

415 Unsupported Media Type

API

[Consumes("multipart/form-data")]
[HttpPost]
public async Task<IActionResult> SendEmail([FromBody]Entity entity)
{
    try
    {

        return OK();
    }
    catch (Exception e)
    {
        throw e;
    }
}

Class

public class Entity 
{
    public List<IFormFile> Files { get; set; }
}

Answer

Dom J picture Dom J · Mar 12, 2018

Try using [FromForm] instead of [FromBody] for the method parameter if you're POSTing form data.