.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 ...
随机推荐
- Alpha(9/10)
鐵鍋燉腯鱻 项目:小鱼记账 团队成员 项目燃尽图 冲刺情况描述 站立式会议照片 各成员情况 团队成员 学号 姓名 git地址 博客地址 031602240 许郁杨 (组长) https://githu ...
- 杭电2000----ASCII码排序
#include<stdio.h> int main() { ]; int i,j,t; while(gets(a)!=NULL) { ; i<; ++i) ; j<-i; + ...
- JS实现缓动动画效果
原理如下: 假设要从数值A变化到数值B,如果是线性运动,则每次移动距离是一样:如果是缓动,每次移动距离不一样.那如何才能不一样呢?很简单,按比例移动就可以. 例如:每次移动剩余距离的一半. 对吧,超容 ...
- Codeforces Round #517 (Div. 2)
A #include<queue> #include<cstdio> #include<cstring> #include<algorithm> #de ...
- 2017-9-8-RaspberryPi安装过程
设备: RaspberryPi 3B 安装版本: 2017-01-11-raspbian-jessie.img 第一步:准备好8G以上tf卡.Win32DiskImager.SD Formatter. ...
- Java代码优化小结(一)
(1)尽量指定类.方法的final修饰符 带有final修饰符的类是不可派生的.在Java核心API中,有许多应用final的例子,例如java.lang.String,整个类都是final的.为类指 ...
- C# 结合html5 批量上传文件和图片预览
html5 新特性 <input id="imgsf" type="file" name="imgsf" multiple /> ...
- 20172327 2018-2019-1 《第一行代码Android》第一章学习总结
学号 2018-2019-1 <第一行代码Android>第一章学习总结 教材学习内容总结 - Android系统架构: 1.Linux内核层 Android系统是基于Linux内核的,这 ...
- 网络 [HNOI2016]
Description 一个简单的网络系统可以被描述成一棵无根树.每个节点为一个服务器.连接服务器与服务器的数据线则看做一条树边.两个服务器进行数据的交互时,数据会经过连接这两个服务器的路径上的所有服 ...
- Linux下安装配置virtualenv与virtualenvwrapper
一.Linux下安装.配置virtualenv 配置源 #指定清华源下载pip的包 [root@localhost opt]# pip3 install -i https://pypi.tuna.ts ...