无法上传使用Net Core进行改装的照片



我试图通过重新安装将照片从web MVC上传到API,但总是返回400个错误请求,客户端发送的数据为空这些是我的代码:

//Refit
[Multipart]
[Post("/api/products/{id}/uploadphoto")]
public Task<ApiResponse<bool>> UploadPhoto(int id,[AliasAs("file")]  StreamPart streamPart);
//Service
public async Task<bool> UpdaloadPhoto2(int id, IFormFile file)
{
var stream = file.OpenReadStream();
StreamPart streamPart = new StreamPart(stream, file.FileName, file.ContentType, file.Name);
var res = await productClient.UploadPhoto(id,streamPart);
if (res.IsSuccessStatusCode)
{
return true;
}
var content = res.Error.Content;
AddErrors(content);
return false;
}
//Comsume
[HttpPost("{id}/uploadphoto")]
public IActionResult UploadPhoto(int id,[FromForm] IFormFile file)
{
var res= productService.UploadPhoto(id,file);
if(res!=null) return Ok();
return BadRequest(); 
}

控制器需要接收IFormFileIList

尝试

public IActionResult UploadPhoto(int id, IList<IFormFile> files)

相关内容

  • 没有找到相关文章

最新更新