Malik Kashmiri
Malik Kashmiri

Reputation: 5861

415 Unsupported Media Type asp.net core

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; }
}

Upvotes: 23

Views: 31734

Answers (3)

Oluwafisayo Owolo
Oluwafisayo Owolo

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

user2502917
user2502917

Reputation: 327

In Postman, when creating a POST request, the default is "Text". Change it to JSON.

Upvotes: 12

Dom
Dom

Reputation: 1816

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

Upvotes: 38

Related Questions