- 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;
- }
- }
- }
- }
.ashx接收APPCAN发送过来的图片数据流,保存为图片
最新推荐文章于 2021-06-05 01:25:01 发布