Warm tip: This article is reproduced from serverfault.com, please click

How to handle images from request body

发布于 2020-11-28 18:48:18

I have a dotnet API server and I want to send images in the request body, but when I make a request from postman I have an error "Unsupported Media Type"
1

here is my API controller, I have changed the argument of the function from an object to a byte array but it does not help, what should I do to be able to send a request with a file in the body as binary to handle it 2

Questioner
AkezhanOb1
Viewed
0
tmsbrndz 2020-11-29 03:08:21

you can get file with IFormFile.

E.g:

[HttpPost]
public ActionResult PostImage([FromForm] IFormFile image){
  if (image == null || image.Length == 0)
  {
     return BadRequest();
  }
  // Do something with image
}