/// <summary>/// 项目文件夹下路径  返回流类型数据,如:图片类型/// </summary>/// <returns></returns>public HttpResponseMessage GetImg(){  //  ~/ ImageFile / 001.png//项目文件夹下路径var imgPath = System.Web.Hosting.HostingEnvironment.MapPath("~/ImageFile/2.jpg");// 从图片中读取bytevar imgByte = File.ReadAllBytes(imgPath);// 从图片中读取流var imgStream = new MemoryStream(File.ReadAllBytes(imgPath));var resp = new HttpResponseMessage(HttpStatusCode.OK){Content = new StreamContent(imgStream)//或者//  Content = new ByteArrayContent(imgByte)
            };resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");return resp;}

 [HttpGet]public HttpResponseMessage SelectUploadFile(){Image img = Image.FromFile(@"C:\ImageFile\2.jpg");MemoryStream ms = new MemoryStream();img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);result.Content = new ByteArrayContent(ms.ToArray());result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); //设置http响应上的Content-Type 为image/Png媒体类型return result;}

异步操作获取文件图片

 [Route("Main")][HttpGet]public async Task<HttpResponseMessage> GetMain(string Ordernumber, int seq = 1){return await Task.FromResult<HttpResponseMessage>(GetFileImage("main", Ordertnumber, seq));}private HttpResponseMessage GetFileImage(string type, string Ordernumber, int seq){string basePath = @"C:\ImageFile\";string filePath = basePath + type + "\\_" + type + "_" + seq.ToString() + ".png";Image img = Image.FromFile(filePath);MemoryStream ms = new MemoryStream();img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);result.Content = new ByteArrayContent(ms.ToArray());result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/Png");return result;}

.NET HttpGet 获取服务器文件下的图片信息 同步和异步方式处理相关推荐

  1. 服务器锁定文件,BEA-141297 - 无法获取服务器文件锁定(BEA-141297 - Could not get the server file lock)...

    BEA-141297 - 无法获取服务器文件锁定(BEA-141297 - Could not get the server file lock) 尝试启动Oracle Weblogic Server ...

  2. Python 对os.listdir()获取的文件列表进行 Windows 的按名称方式排序,natsort 库的应用

    Python 对os.listdir()获取的文件列表进行 Windows 的按名称方式排序,natsort 库的应用 1.前言 日前,使用os.listdir()读取一个文件夹下的所有文件和子文件夹 ...

  3. php获取服务器文件路径,php获取服务器路径

    php获取服务器路径 内容精选 换一换 为加强对系统数据的容灾管理,云堡垒机支持配置日志备份,提高审计数据安全性和系统可扩展性.本小节主要介绍如何在系统配置FTP/SFTP服务器参数,将日志远程备份至 ...

  4. 使用nc获取服务器文件

    一.实现: 1.安装nc 1) Linux系统,Centos为yum install nc 2)windows系统,下载nc.exe,将nc.exe放到C:\Windows\System32目录下 ( ...

  5. vb获取服务器文件路径,vb打开ftp服务器文件路径

    vb打开ftp服务器文件路径 内容精选 换一换 该任务指导用户使用Loader将数据从HDFS/OBS导出到SFTP服务器.创建或获取该任务中创建Loader作业的业务用户和密码.确保用户已授权访问作 ...

  6. 获取Resources文件下图片的精灵格式

    ReviewImg用于显示图片,所挂脚本为ImageName using UnityEngine; using System.Collections; public class ImageName : ...

  7. java怎么获取服务器文件夹,java获取远程服务器的文件夹

    java获取远程服务器的文件夹 内容精选 换一换 工具中所有涉及上传文件功能的,如果需要上传的文件大于1GB或者解压后超过剩余磁盘空间的一半,则需要释放磁盘空间或手动将文件上传至服务器,其他情况可通过 ...

  8. web项目获取webpp文件下的图片

    获取webapp下的某个文件夹中的图片,这样就不需要在服务器上建立一个文件 request.getSession().getServletContext().getRealPath("/im ...

  9. c 怎么获取服务器文件是否存在,powershell - 需要找出服务器上是否存在特定的文件夹。如果是,那么哪个驱动器是C:或D - 堆栈内存溢出...

    我需要找出服务器上Backupeventlog存在名为Backupeventlog文件夹. 如果是,那么哪个驱动器为C:或D:驱动器. 此文件夹也为空,如果不为空,则此文件夹下创建的最新文件的日期是什 ...

最新文章

  1. 屏幕录制工具(可录制GIF)
  2. 利用神经网络 遗传算法求得函数极小极大值
  3. 对计算机图形学知识总结第二版,计算机图形学入门总结!
  4. linux 上删除docker 虚悬镜像
  5. linux shell之xargs 、tr、sha1sum、head、tail一般使用
  6. Codeforces Round #719 (Div. 3)/ Codeforces Round #720 (Div. 2)
  7. java程序员选择多个offer时需要看重哪些?_对不起,我们公司不要本科以下的大学生,学历对于程序员重不重要...
  8. Spring Cloud Ribbon –进行安全呼叫
  9. get方法 服务器响应,HTTP请求方法及响应码详解(http get post head)
  10. Bifrost微前端框架及其在美团闪购中的实践
  11. 孩子看动画片有啥好处?
  12. PHP 中 new static 和 new self 的区别
  13. purcell的emacs配置中的自动补全功能开启
  14. 在线代码图片生成工具carbon
  15. 愚人节的背后:技术在一面打假,一面造假
  16. lempel ziv matlab,使用Lempel-Ziv压缩
  17. h5显示微信公众号文章
  18. 网络原理——网络层与数据链路层
  19. iOS 上的插件化设计
  20. 计算机主机后面的辐射多远,离电脑多远才没有辐射 预防辐射技巧

热门文章

  1. cfile 修改某些位_王者荣耀:打野刀效果再次修改,自定义房间配置试运行!
  2. android sharedpreferences 工具类,android sharedpreferences工具类
  3. 云电脑是什么_云电脑为什么发布新1代5G无影?带你了解PC
  4. 微信小程序云开发 mysql_微信小程序云开发学习笔记(一)云数据库
  5. mysql 临时表增加主键_MySQL之重建表
  6. java中properties作用,java中Properties有什么用,举例说明?
  7. php ci url,URL路由设置-CI(codeigniter)PHP框架再探
  8. 飞机大战-控制玩家飞机左右移动
  9. jq画布插件_超炫HTML 5开发的jQuery进度条插件
  10. python打印进度条starting...done_python打印进度条-tqdm