.NET HttpGet 获取服务器文件下的图片信息 同步和异步方式处理
/// <summary>
/// 项目文件夹下路径 返回流类型数据,如:图片类型
/// </summary>
/// <returns></returns>
public HttpResponseMessage GetImg()
{ // ~/ ImageFile / 001.png
//项目文件夹下路径
var imgPath = System.Web.Hosting.HostingEnvironment.MapPath("~/ImageFile/2.jpg");
// 从图片中读取byte
var 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 = )
{
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 获取服务器文件下的图片信息 同步和异步方式处理的更多相关文章
- Ajax基础(二)--获取服务器文件
获取服务器文件相关步骤: 1.创建文件: 2.创建XMLHttpRequest对象: 3.获取文件(注意事项:1)在服务器中运行测试:2)注意编码问题,编码要统一). 3.1 获取xml文件: HTM ...
- AJAX获取服务器文件
写一个按钮,点击后在指定的div里显示本地txt文件内容 在本地新建一个test.txt,里面随便写点内容就好. <!DOCTYPE html> <html> <head ...
- 获取指定文件下的所有file文件
/** * 描述:获取所有的文件列表 * @param file * @param list * @return */ private List<File> getAllFiles(Fil ...
- 【web】之获取服务器tomcat下webapps目录路径
String realPath = req.getServletContext().getRealPath("/"); String realPathParent=(new Fil ...
- 获取bundle文件下的资源
NSBundle* bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle].resourcePath stringByAppendingPat ...
- ASP.NET获取服务器文件的物理路径
如下: string fullpath = context.Server.MapPath("hello.htm"); //得到hello.htm的全路径 string conten ...
- GET方式,获取服务器文件
package com.http.get; import java.io.FileOutputStream; import java.io.IOException; import java.io.In ...
- python 获取某个文件下的所有文件
import os files = os.listdir(load_Graph_file_path) cnt = 0 for file in files: print(file) if (os.pat ...
- 通过ftp同步服务器文件:遍历文件夹所有文件(含子文件夹、进度条);简单http同步服务器文件实例
该代码主要实现,指定ftp服务地址,遍历下载该地址下所有文件(含子文件夹下文件),并提供进度条显示:另外附带有通过http地址方式获取服务器文件的简单实例 废话不多说,直接上代码: 1.FTPHelp ...
随机推荐
- 【SQL】SQL整表复制
SQL Server中,如果目标表存在: 1 insert into 目标表 select * from 原表; SQL Server中,如果目标表不存在: 1 select * into 目标表 f ...
- pyquery 库的方法
初始化 在这里介绍四种初始化方式. (1)直接字符串 from pyquery import PyQuery as pq doc = pq("<html></html> ...
- SpringBoot多数据源
很多业务场景都需要使用到多数据库,本文介绍springboot对多数据源的使用. 这次先说一下application.properties文件,分别连接了2个数据库test和test1.完整代码如下: ...
- SpringBoot学习历程
新年新气象,更新了一下本人所有写的关于SpringBoot的文章目录,感谢大家长期以来的支持,在接下来的日子还会不定期的进行更新. 入门 使用IntelliJ Idea新建SpringBoot项目 S ...
- POJ2386----Lake Counting
/* 利用宽搜将每块积水填满,添加一个计数器,记下填满几块积水即答案 */ #include<iostream> using namespace std; ][]; ][] = {{-,- ...
- wget用法汇总
wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括Windows在内的各个平台上.它有以下功能和特点: (1)支持断点下传功能:这一点,也是网络蚂蚁和F ...
- Android中,如何提升Layout的性能?
Layout 是 Android 应用中直接影响用户体验的关键部分.如果实现的不好,你的 Layout 会导致程序非常占用内存并且 UI 运行缓慢.Android SDK 带有帮助你找到 Layout ...
- shell脚本使用技巧4--读取字符,重复执行
ls | cat -n > out.txt 给输出的信息加行号并导出到out.txt 利用shell生成一个独立的进程 pwd; (cd /bin; ls); pwd; 开启一个子shell,不 ...
- Python内置GUI模块Tkinter的几点笔记
组件属性,用法 组件位置 更多
- 11-22 JS中级复习
1.this js的关键字, 用途:指向某一个对象. 如何判断this指向 函数(方法)内 一种以函数的方式调用(不带.) this指向winodw 一种以方法的形式调用(函数名前面带.)this指向 ...