BaseController.cs 921 B

123456789101112131415161718192021222324252627282930313233
  1. using Hotline.Api.Filter;
  2. using Microsoft.AspNetCore.Mvc;
  3. using MiniExcelLibs;
  4. using System.IO;
  5. namespace Hotline.Api.Controllers;
  6. [ApiController]
  7. [Produces("application/json")]
  8. [Route("api/v1/[controller]")]
  9. [LogFilter]
  10. public class BaseController : ControllerBase
  11. {
  12. protected FileStreamResult ExcelStreamResult(Stream stream, string fileName = null)
  13. {
  14. var tail = DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx";
  15. fileName = string.IsNullOrEmpty(fileName)
  16. ? tail
  17. : $"{fileName}_{tail}";
  18. HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
  19. return new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  20. {
  21. FileDownloadName = fileName
  22. };
  23. }
  24. }
  25. [ApiController]
  26. [Route("api/v1/[controller]")]
  27. public class OriginController : ControllerBase
  28. {
  29. }