:sparkles:新增文件下载接口

This commit is contained in:
不做码农
2023-12-17 16:25:56 +08:00
parent 7c78ce8ed5
commit 0ee1ab8af5
4 changed files with 56 additions and 24 deletions
@@ -8,6 +8,7 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Web;
namespace Infrastructure.Controllers
@@ -75,6 +76,23 @@ namespace Infrastructure.Controllers
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName));
}
/// <summary>
/// 下载文件
/// </summary>
/// <param name="path"></param>
/// <param name="fileName">文件名,一定要带扩展名</param>
/// <returns></returns>
protected IActionResult DownFile(string path, string fileName)
{
if (!System.IO.File.Exists(path))
{
return NotFound();
}
var stream = System.IO.File.OpenRead(path); //创建文件流
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(stream, "application/octet-stream", HttpUtility.UrlEncode(fileName));
}
#region 方法
/// <summary>