NetCore API 返回文件流

mac2022-06-30  68

    [HttpGet] public IActionResult GetFile(string filepath) { if (string.IsNullOrEmpty(filepath)) filepath = "D:\\ABC.log"; var provider = new FileExtensionContentTypeProvider(); FileInfo fileInfo = new FileInfo(filepath); var ext = fileInfo.Extension; new FileExtensionContentTypeProvider().Mappings.TryGetValue(ext,out var contenttype); return File(System.IO.File.ReadAllBytes(filepath), contenttype ?? "application/octet-stream", fileInfo.Name); }

原来有方法可以获取到contenttype,忘了。

转载于:https://www.cnblogs.com/huanyun/p/11310659.html

相关资源:Web Api 通过文件流 下载文件到本地实例
最新回复(0)