I try to Upload a photo from web MVC to API by refit but alway return 400 bad request and data send from client is null These are my codes:
//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();
}