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

c#-如何处理请求正文中的图像

(c# - How to handle images from request body)

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

我有一个dotnet API服务器,我想在请求正文中发送图像,但是当我从 Postman 发出请求时,出现错误“不支持的媒体类型”
1个

这是我的API控制器,我已将函数的参数从对象更改为字节数组,但无济于事,我应该怎么做才能将带有文件的请求作为二进制文件发送给主体以处理该请求 2个

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

你可以使用来获取文件IFormFile

例如:

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