- 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发送过来的图片数据流,保存为图片
最新推荐文章于 2020-12-20 14:38:09 发布
本文介绍了一个用于处理图片上传的ASP.NET类ImageHandler。该类通过获取HTTP请求中的文件,并将它们保存到指定路径下。它使用System.Drawing命名空间来处理图片,并能够支持多个文件上传。
4190

被折叠的 条评论
为什么被折叠?



