.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"));
        }

测试

前端展示

相关推荐
Warson_L1 小时前
Python 流程控制与逻辑
后端·python
糖炒栗子03261 小时前
架构笔记:应用配置无状态化 (Statelessness)
后端
Warson_L1 小时前
Python 四大组合数据类型 (Collection Types)
后端·python
查古穆2 小时前
大白话讲ReAct:大模型的“边想边干”
后端
于先生吖2 小时前
SpringBoot+MQTT 无人健身房智能管控系统源码实战
java·spring boot·后端
毕设源码-小云学姐2 小时前
计算机毕业设计springboot网上招聘系统 基于SpringBoot的在线人才对接平台设计与实现 SpringBoot框架下的数字化求职招聘服务系统开发
spring boot·后端·课程设计
weyyhdke4 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
ywf12154 小时前
Go基础之环境搭建
开发语言·后端·golang
Victor3564 小时前
MongoDB(76)如何配置防火墙规则?
后端
Victor3564 小时前
MongoDB(75)如何配置TLS/SSL加密?
后端