Пример #1
0
        public async Task <ActionResult> DownloadDatasets(string datasetId)
        {
            string filename;
            var    fileStream = _exportService.DownloadDataset(datasetId, out filename);

            if (fileStream == null)
            {
                return(NotFound("cannot file ddlkjaskjh "));
            }

            HttpContext.Response.Clear();
            Response.ContentType = "application/octet-stream";
            Response.Headers.Add("content-disposition", "attachment");
            Response.Headers.Add("x-filename", filename + ".csv");
            Response.Headers.Add("content-length", fileStream.Length.ToString());
            Response.Headers.Add("Access-Control-Expose-Headers", "x-filename , content-length, content-disposition");
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            await fileStream.CopyToAsync(HttpContext.Response.Body);

            fileStream.Close();
            return(new FileStreamResult(fileStream, "text/csv")
            {
                FileDownloadName = filename + ".csv"
            });
        }