您的位置:首页 > 移动开发

.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;  

            }  

        }  

    }  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: