Search code examples
restasp.net-web-apihttp-method

Send IformData as a field within Postman


This is my postman setup;

enter image description here

for the request object;

public class UploadRequest
    {
        public List<IFormFile> File { get; set; }
        public int EntityType { get; set; }
        public int ReferenceId { get; set; }
    }

And it returns "Unsupported Media Type" status code 415

here is the API

[AllowAnonymous]
[HttpPost("api/[namespace]")]
public override async Task<ActionResult> HandleAsync([FromBody] UploadRequest request)
{

How can I post these data properly?


Solution

  • You did accept the parameter from Body ([FromBody]) but you did use Form when sending photos and values. Update your HandleAsync method to accept the data from the multipart/form-data request with the [FromForm] attribute.

    [AllowAnonymous]
    [HttpPost("api/[namespace]")]
    public override async Task<ActionResult> HandleAsync([FromForm] UploadRequest request)
    {
       //code logic
    }