.NET WebApi返回图片

参考

asp.net web api返回图片至前端 - GUOKUN - 博客园 (cnblogs.com)

vue获取图片流数据并展示_vue展示图片流-CSDN博客

后端返回

核心代码

ini 复制代码
        [HttpGet]
        public async Task<IActionResult> GetPic()
        {
            MemoryStream stream;
            using (FileStream fileStream = new FileStream("Image/2.png", FileMode.Open))
            {
                int len = (int)fileStream.Length;
                byte[] buf = new byte[len];
                fileStream.Read(buf, 0, len);
                stream = new MemoryStream();
                stream.Write(buf, 0, len);
            }
            return await Task.FromResult<FileResult>(File(stream.ToArray(), "image/jpeg"));
        }

测试

前端展示

相关推荐
0xDevNull18 分钟前
Linux 中 Nginx 代理 Redis 的详细教程
redis·后端
GetcharZp34 分钟前
告别 Nginx 手动配置!这款 Go 语言开发的云原生网关,才是容器化时代的真香神器!
后端
RuoyiOffice43 分钟前
SpringBoot+Vue3 企业考勤如何处理法定假期?节假日方案、调休补班与工作日判断链路拆解
spring boot·后端·vue·anti-design-vue·ruoyioffice·假期·人力
Vane11 小时前
从零开发一个AI插件,经历了什么?
人工智能·后端
952362 小时前
SpringBoot统一功能处理
java·spring boot·后端
rleS IONS2 小时前
SpringBoot中自定义Starter
java·spring boot·后端
DevilSeagull2 小时前
MySQL(2) 客户端工具和建库
开发语言·数据库·后端·mysql·服务
TeDi TIVE3 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
雨辰AI3 小时前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking
Nicander4 小时前
理解 mybatis 源码:vibe-coding一个mini-mybatis
后端·mybatis