Reputation: 5861
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
[Consumes("multipart/form-data")]
[HttpPost]
public async Task<IActionResult> SendEmail([FromBody]Entity entity)
{
try
{
return OK();
}
catch (Exception e)
{
throw e;
}
}
public class Entity
{
public List<IFormFile> Files { get; set; }
}
Upvotes: 23
Views: 31734
Reputation: 49
In Postman, after ensuring that you're using raw and its in JSON format. Most especially when making GET request and you're not sending any data in the body of the request ensure that the body of the request is not empty. It must have an empty object: { }
Upvotes: 3
Reputation: 327
In Postman, when creating a POST request, the default is "Text". Change it to JSON.
Upvotes: 12
Reputation: 1816
Try using [FromForm]
instead of [FromBody]
for the method parameter if you're POSTing form data.
Upvotes: 38