我尝试IFormFile使用邮递员插件上传照片。但是 API 没有从请求正文中获取文件对象。我试过有和没有[FromBody]。
[HttpPost]
public async Task<IActionResult> Upload(int vId, IFormFile fileStream)
{
var vehicle = await this.repository.GetVehicle(vId, hasAdditional: false);
if (vehicle == null)
return NotFound();
var uploadsFolderPath = Path.Combine(host.WebRootPath, "uploads");
if (!Directory.Exists(uploadsFolderPath))
Directory.CreateDirectory(uploadsFolderPath);
var fileName = Guid.NewGuid().ToString() + Path.GetExtension(fileStream.FileName);
var filePath = Path.Combine(uploadsFolderPath, fileName);
using (var stream = new FileStream(filePath, FileMode.Create))
{
await fileStream.CopyToAsync(stream);
}
该错误在这条线显示:
var fileName = Guid.NewGuid().ToString() + Path.GetExtension(fileStream.FileName);
我发现它没有获取文件,而我正在发送具有相同密钥的 image.jpg "fileStream"。顺便说一句,其他一切正常。我找不到解决此问题的解决方案。如果有人可以帮助我,请告诉我。
慕桂英4014372
一只名叫tom的猫
相关分类