public void ProcessRequest(HttpContext context) { int MediaClassId = 0; string MediaScale = ""; int smallPiexl = 0; int WaterMark = 0; string WaterImagePath = ""; int waterPosition = 0; string MediaLabel = ""; string MediaDescript = ""; string MediaTitle = ""; MediaClassId = int.Parse(context.Request["MediaClassId"].ToString()); MediaScale = context.Request["MediaScale"].ToString(); smallPiexl = int.Parse(context.Request["smallPiexl"].ToString()); WaterMark = int.Parse(context.Request["WaterMark"].ToString()); WaterImagePath = context.Request["WaterImagePath"].ToString(); waterPosition = int.Parse(context.Request["waterPosition"].ToString()); if (!string.IsNullOrEmpty(context.Request["MediaLabel"])) { MediaLabel = context.Request["MediaLabel"].ToString(); } if (!string.IsNullOrEmpty(context.Request["MediaLabel"])) { MediaLabel = context.Request["MediaLabel"].ToString(); } if (!string.IsNullOrEmpty(context.Request["MediaDescript"])) { MediaDescript = context.Request["MediaDescript"].ToString(); } if (!string.IsNullOrEmpty(context.Request["MediaTitle"])) { MediaTitle = context.Request["MediaTitle"].ToString(); } context.Response.ContentType = "text/plain"; HttpPostedFile file = context.Request.Files["Filedata"];//接受文件 string fileExt = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1); if (!FileHelper.CheckFileExt(this.fileType, fileExt)) { context.Response.Write("不允许上传" + fileExt + "类型的文件"); } if (this.fileSize > 0 && file.ContentLength > fileSize * 1024) { context.Response.Write("文件超过限制的大小啦"); } MediaSize = file.ContentLength / 1024; filename = DateTime.Now.ToString("ddHHmmssfff") + Path.GetExtension(file.FileName); localPath = HttpContext.Current.Request.PhysicalApplicationPath + ("upimg/" + DateTime.Now.ToString("yyyyMM") + "/"); //判断文件夹是否存在, 不存在则创建 if (!System.IO.Directory.Exists(localPath)) { System.IO.Directory.CreateDirectory(localPath); } try { //本地创建上传的图片文件 file.SaveAs(Path.Combine(localPath, filename)); } catch (Exception) { strfile = "Error"; } string path = "/upimg/" + DateTime.Now.ToString("yyyyMM") + "/" + filename; byte[] Data = new byte[1]; Data = FileHelper.AddImageSignPic(File.ReadAllBytes(localPath + filename), path, WaterImagePath, waterPosition, waterQuality, waterTransparency, WaterMark); //读取本地图片, 转成二进制, 调用服务生成图片, 返回路径另上域名 if (FileServer.CreateFileImage(Data, path)) { strfile = "http://img.stock.com" + path; } else { strfile = "Error"; } //判断文件是否存在, 存在则删除 // if (File.Exists(localPath + filename)) // File.Delete(localPath + filename); Media Media = new Media(); MediaBLL MediaBLL = Factory.BusinessFactory.CreateBll <MediaBLL>(); if (!string.IsNullOrEmpty(path)) { Media.MediaClassId = MediaClassId; Media.MediaTitle = MediaTitle; Media.UploadTime = DateTime.Now; Media.UploadPath = path; Media.MediaSize = MediaSize; Media.MediaType = 1; Media.Uploader = UserCookies.AdminName; Media.MediaLabel = MediaLabel; Media.MediaDescript = MediaDescript; MediaBLL.Add(Media).ToString(); } context.Response.Write("/upimg/" + DateTime.Now.ToString("yyyyMM") + "/" + filename); }
public string UploadPic(Media Media, string MediaScale, int WaterMark, int smallPiexl, string WaterImagePath, int waterPosition, string UploadType) { UpLoadMedia upLoadMedia = new UpLoadMedia(); string upfilepath = HttpContext.Current.Request.QueryString["Filedata"]; //取得上传的对象名称 HttpPostedFile upfile = HttpContext.Current.Request.Files[upfilepath]; if (upfile == null) { return("请选择图片"); } upLoadMedia.WaterPath = WaterImagePath; upLoadMedia.MediaScale = MediaScale; if (MediaScale == "h") { upLoadMedia.ThumbNail_Height = smallPiexl; } else { upLoadMedia.ThumbNail_Width = smallPiexl; } upLoadMedia.WaterPostion = waterPosition; string msg = upLoadMedia.fileSaveAs(upfile, WaterMark); if (!string.IsNullOrEmpty(UpLoadMedia.UploadPath)) { if (UploadType == "add") { Media.MediaClassId = Media.MediaClassId; Media.MediaTitle = Media.MediaTitle; Media.UploadTime = DateTime.Now; Media.UploadPath = UpLoadMedia.UploadPath; Media.MediaSize = UpLoadMedia.MediaSize; Media.MediaType = Media.MediaType; Media.Uploader = UserCookies.AdminName; Media.MediaLabel = Media.MediaLabel; Media.MediaDescript = Media.MediaDescript; MediaBLL.Add(Media).ToString(); } else { Media.MediaId = Media.MediaId; Media.MediaClassId = Media.MediaClassId; Media.MediaTitle = Media.MediaTitle; Media.UploadTime = DateTime.Now; Media.UploadPath = UpLoadMedia.UploadPath; Media.MediaSize = UpLoadMedia.MediaSize; Media.MediaType = Media.MediaType; Media.Uploader = UserCookies.AdminName; Media.MediaLabel = Media.MediaLabel; Media.MediaDescript = Media.MediaDescript; MediaBLL.Update(Media).ToString(); } upfile.InputStream.Close(); upfile.InputStream.Dispose(); return("操作成功"); } else { return(msg); } }