asp dotnet core 提供大文件下载的测试
本文仅仅是提供测试使用的代码。提供文件下载只需要返回 PhysicalFile 方法,如下面代码:public IActionResult Get()
{
var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var file = Path.Combine(folder, "big file");
const string mime = "application/octet-stream";
return PhysicalFile(file, mime);
} 本文的 big file 是程序运行创建的垃圾文件:
private void WriteBigFile()
{
var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var file = Path.Combine(folder, "big file");
if (!File.Exists(file))
{
using (var stream = new FileStream(file, FileMode.Create))
{
for (int i = 0; i < 100000000; i++)
{
stream.WriteByte(0);
}
}
}
}
页:
[1]