public async Task <IActionResult> Download(int id, [FromQuery(Name = "token")] string tokenString) { if (tokenString == null) { throw new ArgumentNullException(nameof(tokenString)); } if (id <= 0) { throw new ArgumentOutOfRangeException(nameof(id)); } var token = _tokenProvider.ReadToken(tokenString); _sessionContext.InitFromClaims(token.Claims.ToArray()); var fileRow = _fileRepository.Get(id); if (fileRow == null) { return(NotFound()); } var stream = await _storage.Load(fileRow.FilePath); return(File(stream, fileRow.ContentType, fileRow.FileName)); }