.net core 实现文件下载

https://zhuanlan.zhihu.com/p/35053877

 

文件下载

找到指定的文件,转换成流,通过.net core自带的File方法返回流文件,完成文件下载:

[HttpGet("download")]
public async Task<IActionResult> Get(string fileName)
{
    try
    {
        var addrUrl = Path.Combine(Directory.GetCurrentDirectory(), BASEFILE, $@"{fileName}");
        FileStream fs = new FileStream(addrUrl, FileMode.Open);
        return File(fs, "application/vnd.android.package-archive", fileName);
    }
    catch(Exception ex)
    {
        return NotFound();
    }
}
上一篇:消息智能路由组件SmartRoute


下一篇:Unity Fileinfo和Directoryinfo以及File与Filestream还有Streamwriter和Streamreader