.ashx接收APPCAN发送过来的图片数据流,保存为图片
2018-01-16 10:24
323 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Drawing;
using System.Web.SessionState;
namespace BlankOrder
{
/// <summary>
/// ImageHandler 的摘要说明
/// </summary>
public class ImageHandler : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
var httpRequest = System.Web.HttpContext.Current.Request;
HttpFileCollection uploadFiles = httpRequest.Files;
try
{
//int vals = context.Request.TotalBytes;
//byte[] buffer = context.Request.BinaryRead(vals);
string imgname = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
string filePath = "/img/userupphoto/" + imgname;
if (context.Request.Files.Count > 0)
{
int i;
for (i = 0; i < uploadFiles.Count; i++)
{
HttpPostedFile postedFile = uploadFiles[i];
Image img = new Bitmap(postedFile.InputStream);
img.Save(context.Server.MapPath(filePath));
img.Dispose();
}
}
}
catch (Exception e)
{
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Drawing;
using System.Web.SessionState;
namespace BlankOrder
{
/// <summary>
/// ImageHandler 的摘要说明
/// </summary>
public class ImageHandler : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
var httpRequest = System.Web.HttpContext.Current.Request;
HttpFileCollection uploadFiles = httpRequest.Files;
try
{
//int vals = context.Request.TotalBytes;
//byte[] buffer = context.Request.BinaryRead(vals);
string imgname = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
string filePath = "/img/userupphoto/" + imgname;
if (context.Request.Files.Count > 0)
{
int i;
for (i = 0; i < uploadFiles.Count; i++)
{
HttpPostedFile postedFile = uploadFiles[i];
Image img = new Bitmap(postedFile.InputStream);
img.Save(context.Server.MapPath(filePath));
img.Dispose();
}
}
}
catch (Exception e)
{
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
相关文章推荐
- .ashx接收APPCAN发送过来的图片数据流,保存为图片
- 通过数据流发送接收图片
- PHP post 接口上传图片 [接收ios ||androip 两种接收图片数据流保存图片方式]
- C#远程发送和接收数据流生成图片的方法
- java&nbsp;发送字节流图片,c++接收二进…
- Flex接收51单片机发送过来的16进制数据转换为String
- 使用字节流、客户端读取图片发送至服务端保存
- 微信公众号开发接收图片消息,获取用户发送图片的media_id
- 用C#保存IOS发送的图片
- Socket多人聊天(文字+图片+多文件发送和接收)
- Flex接收51单片机发送过来的16进制数据转换为String
- C#使用Socket实现发送和接收图片的方法
- VPOS MAS-CNP接口——接收通过https发送来的XML数据流
- 地磅称量系统之(60) 接收地磅发送过来的数据显示在LCD上
- ASP.NET Web API 发送接收图片参考
- 接收图片二进制流并保存图片
- 发送广播重新挂载SD卡,使图库可以及时显示自己保存的图片(无需手机重启)
- asp.net mvc中action接收客户端发送过来的html片段
- Java模块 -- Http发送post数据文件,服务端Servlet接收,保存至本地
- andrid 上传图片 asp.net 后台接收并保存