I've created a simple controller for uploading and getting a (static) cached image. I know it's not the best practice to have a static byte array but it's just for test purposes.
It works as expected except there's always about 60-80% data missing from the image when I'm trying to download it.
[Route("image")]
public class CameraController : ControllerBase
{
private static byte[] latestImageData;
[HttpPost("upload")]
public async Task<ActionResult> PostData()
{
if(HttpContext.Request.ContentType == "image/jpeg")
{
var contentLength = Convert.ToInt32(HttpContext.Request.ContentLength);
latestImageData = new byte[contentLength];
await HttpContext.Request.Body.ReadAsync(latestImageData);
}
return NoContent();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[HttpGet("get")]
public ActionResult GetImage()
{
if (latestImageData != null)
{
return File(latestImageData, "image/jpeg");
}
else
return NoContent();
}
}
This is the result I'm getting when I'm trying to download the image:
Any ideas?