123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Bowin.Common.Utility;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
- {
- [Route("api/systemsetting/[controller]")]
- [ApiController]
- public class ReportController : ControllerBase
- {
- [HttpGet]
- public ActionResult Get(string filePath)
- {
- if (!filePath.Contains(Configuration.Current.AppSettings.TemplatePath))
- filePath = $"{Configuration.Current.AppSettings.TemplatePath}/{filePath}";
- if (filePath.Contains("../") || filePath.Contains("..\\"))
- {
- throw new Exception("不支持返回上级目录");
- }
- var extName = Path.GetExtension(filePath);
- if (extName != ".pdf")
- {
- throw new Exception("只能下载Pdf文件");
- }
- var physicalPath = HttpHelper.MapPath(filePath);
- var pdfStream = System.IO.File.Open(physicalPath, System.IO.FileMode.Open);
- var data = new byte[pdfStream.Length];
- pdfStream.Read(data);
- pdfStream.Close();
- var memoryStream = new MemoryStream(data);
- System.IO.File.Delete(physicalPath);
- return File(memoryStream, "application/pdf");
- }
- }
- }
|