public async Task <ActionResult <Stream> > Get(long primaryKey, CancellationToken cancellationToken) { try { FileStorage currentWorkingObject = await _fileStorageManager.GetAsync(primaryKey, cancellationToken); if (currentWorkingObject.Id != 0) { StreamContent returnFileContent = new StreamContent(currentWorkingObject.FileData); returnFileContent.Headers.ContentType = new MediaTypeHeaderValue(currentWorkingObject.ContentType); returnFileContent.Headers.ContentLength = currentWorkingObject.FileData.Length; return(Ok(await returnFileContent.ReadAsStreamAsync(cancellationToken))); } else { return(NotFound()); } } catch (Exception apiControllerError) { _applicationLogTools.LogError(apiControllerError, new Dictionary <string, dynamic> { { "ClassName", "WebApi.FileStorageController" } }); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development", StringComparison.InvariantCultureIgnoreCase)) { return(base.StatusCode(500, apiControllerError)); } else { return(base.StatusCode(500)); } } }