: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
@@ -151,6 +151,36 @@ namespace ZR.Admin.WebApi.Controllers
#endregion
/// <summary>
/// 下载文件
/// </summary>
/// <param name="path"></param>
/// <param name="fileId"></param>
/// <returns></returns>
[HttpGet]
[Verify]
[ActionPermissionFilter(Permission = "common")]
[Log(Title = "下载文件", IsSaveResponseData = false)]
public IActionResult DownloadFile(string? path, long fileId = 0)
{
var tempPath = path;
if (fileId > 0)
{
var fileInfo = SysFileService.GetById(fileId);
if (fileInfo != null)
{
tempPath = fileInfo.FileUrl;
}
}
string fullPath = tempPath;
if (tempPath.StartsWith("/"))
{
fullPath = Path.Combine(WebHostEnvironment.WebRootPath, tempPath.ReplaceFirst("/", ""));
}
string fileName = Path.GetFileName(fullPath);
return DownFile(fullPath, fileName);
}
/// <summary>
/// 初始化种子数据
/// </summary>