public JsonResult UploadGoodsImg() { byte[] byData = null; JsonResult result = null; tbClientUser clientuser = GetUser("UserInfo"); string RootFilePath = MYDZ.Business.StaticSystemConfig.soft.RootFilePath; try { System.Web.HttpPostedFileBase file = Request.Files["fileToUpload"]; if (file == null) { return(null); } if (file.ContentLength > 500 * 1024) { return(Json(new { URL = "", ErrorMsg = "大于500KB,上传失败!" })); } string hzm = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1).ToLower(); if (hzm != "jpg" && hzm != "gif" && hzm != "png") { return(Json(new { URL = "", ErrorMsg = "选择的文件不是图片文件!" })); } using (Stream stream = file.InputStream) { byData = new Byte[stream.Length]; stream.Position = 0; stream.Read(byData, 0, byData.Length); stream.Close(); } string PictureCategoryName = "商品图片-魔云店长"; string cid = CheckPictureSpace(PictureCategoryName); if (cid == null) { return(null); } string errormsg = null; PictureUpload pu = new PictureUpload(); pu.ImageInputTitle = file.FileName; pu.PictureCategoryId = long.Parse(cid); pu.Img = byData; Picture picture = new Picture(); picture = sgi.PictureUpload(pu, clientuser.UserShops[0].SessionKey, out errormsg); if (errormsg == null) { result = Json(new { URL = picture.PicturePath, ErrorMsg = "" }); } } catch (Exception ex) { throw ex; } return(result); }
protected void PictureUploadSubmit_Click(object sender, EventArgs e) { if (Page.IsValid && PictureUpload.HasFile) { newTemporaryPicture.Save(AppSettings.FolderPaths.BannerAdvertImages); NewCustomGroup.BannerImage = newTemporaryPicture; createBannerAdvertisement_BannerImage.ImageUrl = NewCustomGroup.BannerImage.Path; //Hide upload PictureUpload.Visible = false; PictureUploadSubmit.Visible = false; PictureUpload.Dispose(); } }
protected void FileUploaded(object sender, PictureUpload.FileUploadEventArgs e) { TextBox boundControl = (TextBox)DetailsView1.FindControl("txtPictureURL"); boundControl.Text = e.FileName; }
/// <summary> /// 上传单张图片 /// </summary> /// <param name="PicUpload"></param> /// <param name="token"></param> /// <param name="errorMsg"></param> /// <returns></returns> public Picture PictureUpload(PictureUpload PicUpload, string token, out string errorMsg) { return(sgi.PictureUpload(PicUpload, token, out errorMsg)); }
/// <summary> /// 上传单张图片 /// </summary> /// <param name="PicUpload"></param> /// <param name="sessionKey"></param> /// <param name="errorMsg"></param> /// <returns></returns> internal Picture PictureUpload(PictureUpload PicUpload, string sessionKey, out string errorMsg) { errorMsg = null; ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json"); PictureUploadRequest req = new PictureUploadRequest(); if (PicUpload.PictureCategoryId != null) { req.PictureCategoryId = PicUpload.PictureCategoryId; } else { errorMsg = "图片分类ID不能为空!"; return(null); } if (PicUpload.Img != null) { FileItem fItem = new FileItem("ImageName", PicUpload.Img); req.Img = fItem; } else { errorMsg = "上传图片内容不能为空!"; return(null); } if (PicUpload.ImageInputTitle != null) { req.ImageInputTitle = PicUpload.ImageInputTitle; } else { errorMsg = "图片标题不能为空!"; return(null); } if (PicUpload.Title != null) { req.Title = PicUpload.Title; } if (PicUpload.ClientType != null) { req.ClientType = PicUpload.ClientType; } PictureUploadResponse response = client.Execute(req, sessionKey); if (response.IsError) { errorMsg = response.SubErrMsg; return(null); } Top.Api.Domain.Picture pic = response.Picture; Picture newpic = new Picture(); newpic.ClientType = pic.ClientType; newpic.Created = pic.Created; newpic.Deleted = pic.Deleted; newpic.Md5 = pic.Md5; newpic.Modified = pic.Modified; newpic.PictureCategoryId = pic.PictureCategoryId; newpic.PictureId = pic.PictureId; newpic.PicturePath = pic.PicturePath; newpic.Pixel = pic.Pixel; newpic.Referenced = pic.Referenced; newpic.Sizes = pic.Sizes; newpic.Status = pic.Status; newpic.Title = pic.Title; newpic.Uid = pic.Uid; return(newpic); }