123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
-
- namespace AdService.Controller.Controllers
- {
- /// <summary>
- /// 采集文件操作接口
- /// </summary>
- public class AdFileController : BaseController
- {
- /// <summary>
- /// 下载采集文件
- /// </summary>
- /// <param name="fileName">采集返回的名称</param>
- /// <param name="path">采集返回的文件路径</param>
- /// <returns></returns>
- [HttpGet]
- public IActionResult Download(string path, string fileName)
- {
- if (string.IsNullOrWhiteSpace(fileName))
- {
- return NotFound("必须指定要下载的文件");
- }
- if (fileName.StartsWith("/"))
- fileName = fileName.Substring(1);
- string localFile = Path.Combine(path, fileName);
- try
- {
- if (!System.IO.File.Exists(localFile))
- {
- //IpsLogger.Error($"下载失败,文件[{localFile}]不存在");
- return NotFound($"文件[{fileName}]不存在");
- }
- var fileStream = new FileStream(localFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, true); //异步读取文件
- return File(fileStream, "application/octet-stream", fileName, true); //为true时,支持断点续传
- }
- catch (Exception ex)
- {
- //IpsLogger.Error($"文件[{localFile}]下载失败", ex);
- return NotFound($"文件[{fileName}]下载失败");
- }
- }
- }
- }
|