perf: 使用 FileStreamResult 流式返回文件,避免一次性读取到内存

改为 FileStream 并返回 FileStreamResult,减小内存占用并支持大型文件;修正变量名拼写并添加 null-forgiving 标记。
This commit is contained in:
chenchun
2025-11-06 11:13:50 +08:00
parent 22ac150acd
commit 94834f45c3

View File

@@ -43,8 +43,9 @@ namespace Yi.Framework.Rbac.Application.Services
{
return new NotFoundResult();
}
var steam = await File.ReadAllBytesAsync(path);
return new FileContentResult(steam, file.GetMimeMapping());
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
return new FileStreamResult(stream, file!.GetMimeMapping());
}
/// <summary>