I'm trying to create a REST service that is able to accept form-data. I am using the [FromForm]
attribute but the object's properties are filled with null values.
I have the following endpoint:
[HttpPost("upload")]
public ActionResult<UploadResponse> Upload([FromForm] UploadRequest req)
{
...do something
}
UploadRequest.cs:
public class UploadRequest
{
public IFormFile File { get; set; }
public string Format { get; set; }
public string CaseId { get; set; }
public string Description { get; set; }
}
I post form-data using Postman like this:
The request parameter is filled with null values, though:
I have tried matching the case of parameters, adding and removing "multipart/form-data" header but nothing works for me. What am I missing?
After having a rough time seeking for a solution I found out that I was missing boundary in Content-Type header. So the Content-Type header should look as following: multipart/form-data; boundary=<calculated when request is sent>
.