public async Task <IActionResult> Export([FromBody] ElasticSearchQuery query, [FromQuery] string language) { var userId = User.Claims.FirstOrDefault(s => s.Type == "sub").Value; var result = await _leadRepository.Export(query, language, userId); var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/Export", result); var memory = new MemoryStream(); using (var stream = new FileStream(path, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; return(File(memory, GetContentType(path), $"{Path.GetFileName(path)}_{DateTime.Now.ToString("yyyyMMddHHmmss")}")); }