I'm trying to create a file upload endpoint, but it looks like the only requests that get through have to specify application/json
as the content type. Here is what my endpoint looks like:
[HttpPost()]
public async Task<IActionResult> CreateFile([FromBody] IFormFile contents)
I'm running .NET Core 2.0, and my startup.cs is pretty much just stock. What am I doing wrong?
Your FromBody
makes model binder think it should expect JSON formatted body. You either need to remove [FromBody]
or put [FromForm]
.
The [FromBody]
attribute indicates that that request body should be JSON (or another formatter such as XML, if you've enabled it). If you're uploading a binary, you should either use [FromForm]
or just don't use an attribute at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.