I'm using Postman to test a .Net Core 2.1 Web API. I started with this and it worked -- I was able to send a file from Postman to my Web API.
Web.API
[HttpPost("uploads")]
public IActionResult FileUpload(IFormFile myfile)
{
...
return Ok();
}
However, I need to pass some additional form data along with the file. Based on other posts that I've seen, I tried the following:
[HttpPost("uploads")]
public IActionResult FileUpload(UploadFile data)
{
...
return Ok();
}
public class UploadFile {
public IFormFile myfile {get; set;}
public bool forceOverwrite {get; set;}
}
Now posting from Postman results in "The input was not valid". I've done some searching and can't seem to find anybody that has gotten something like this working.
Update
I also tried the following; however, the additional value always comes in false -- even when sent as true.
public IActionResult FileUpload(IFormFile myfile, bool forceOverwrite)
Update 2
Here is what I added in Postman, and also how it appears in Fiddler. (P.S. You can ignore the fact that the route in the POST doesn't match the route listed in my code -- I chose to simplify things for the post in regards to naming.
For binding FormData in .NET Core Web API, you will need to add FromForm
attribute like below
[HttpPost("uploads")]
public IActionResult FileUpload([FromForm]UploadFile data)
{
return Ok();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With