public async Task <IActionResult> GetProfileImage(AuthorizedProfileImageViewModel viewModel) { CreateDirectories(); if (ModelState.IsValid) { var photoPath = await photoRepo.GetPhotoPath(viewModel.Email); if (photoPath == null) { return(NotFound()); } FileStream imageStream; //if (viewModel.IsThumb) //imageStream = System.IO.File.OpenRead(photoPath.PhotoPath.Replace(".", "THUMB.")); //else imageStream = System.IO.File.OpenRead(photoPath.PhotoPath); var dotSplits = Path.GetFileName(photoPath.PhotoPath).Split('.'); return(File(imageStream, $"image/{dotSplits[dotSplits.Length - 1]}")); } return(BadRequest(ModelState)); }
public static async Task <ResponseResult <byte[]> > GetProfileImagePersistent(string email, bool isThumb) { using (var request = new HttpRequestMessage(HttpMethod.Get, $"{URI}/GetProfileImage")) { var viewModel = new AuthorizedProfileImageViewModel { Email = email, IsThumb = isThumb }; request.Content = new StringContent(JsonConvert.SerializeObject(viewModel), Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); if (response.StatusCode == HttpStatusCode.OK) { return(new ResponseResult <byte[]>( true, await response.Content.ReadAsByteArrayAsync() )); } return(new ResponseResult <byte[]>(false, null)); } }