安卓向.net core api传输图片,执行保存到数据库命令后返回400错误代码,用postman测试没有问题安卓程序不行,其他api没有问题,在执行保存到数据库命令之前也没有问题。希望各位大佬可以帮我解决一下问题,.net core代码如下:
[HttpPost]
[Route("UploadImage")]
public async Task UploadImageAsync(IFormFile tx, [FromForm]string userId)
{
try
{
Account account = await _context.Account.FirstAsync(a => a.UserId == int.Parse(userId));
MemoryStream memory = new MemoryStream();
tx.CopyTo(memory);
account.UserPhoto = memory.ToArray();
account.UserPhotoType = tx.ContentType;
// return Ok(account.UserPhotoType+account.UserPhoto);
//return Ok(tx.FileName + " " + userId + " " + account.UserId);
_context.Update(account);
await _context.SaveChangesAsync();
return Ok("123456789");
}
catch (Exception e)
{
return BadRequest(new { state = "Error", msg = e.Message ,trace=e.StackTrace});
}
}