❤️ 关注 Furion 微信公众号有惊喜哦!
🫠 遇到问题了
Skip to main content

One post tagged with "upload"

View All Tags

2. 文件上传下载

· 2 min read
dotNET China
让 .NET 开发更简单,更通用,更流行。

文件下载

[HttpGet, NonUnify]
public IActionResult FileDownload(string path, string fileName)
{
string filePath = "这里获取完整的文件下载路径";
return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
}
关于前端获取文件名

如果前端获取不到文件夹,可添加以下配置:

_httpContextAccessor.HttpContext.Response.Headers.Add("Content-Disposition", $"attachment; filename={文件名}");
_httpContextAccessor.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");