public async Task <ActionResult <SheriffDto> > UploadPhoto(Guid?id, string badgeNumber, IFormFile file) { await CheckForAccessToSheriffByLocation(id, badgeNumber); if (file.Length == 0) { return(BadRequest("File length = 0")); } if (file.Length >= _uploadPhotoSizeLimitKB * 1024) { return(BadRequest($"File length: {file.Length/1024} KB, Maximum upload size: {_uploadPhotoSizeLimitKB} KB")); } await using var ms = new MemoryStream(); await file.CopyToAsync(ms); var fileBytes = ms.ToArray(); if (!fileBytes.IsImage()) { return(BadRequest("The uploaded file was not a valid GIF/JPEG/PNG.")); } var sheriff = await SheriffService.UpdateSheriffPhoto(id, badgeNumber, fileBytes); return(Ok(sheriff.Adapt <SheriffDto>())); }