public override JsonResult Save() { #region 数据校验 MpMediaVideo entity = UpdateEntity<MpMediaVideo>(); if (string.IsNullOrEmpty(entity.FileID)) throw new BusinessException("视频不能为空"); if (string.IsNullOrEmpty(entity.Title)) throw new BusinessException("标题不能为空"); #endregion #region 微信处理 if (entity.IsDelete == null) entity.IsDelete = 0; if (string.IsNullOrEmpty(entity.MpID)) entity.MpID = GetQueryString("MpID"); if (entity._state == EntityStatus.added.ToString()) { var wxFO = Formula.FormulaHelper.CreateFO<WxFO>(); FsFileInfo fileInfo = masterService.GetFileInfo(entity.FileID, WeChatConfig.FileServerName); if (fileInfo == null) throw new Exception("找不到视频文件"); var mediaid = wxFO.AddVideoFile(entity.MpID, fileInfo.FileFullPath, entity.Title, entity.Description); entity.MediaID = mediaid; } #endregion #region 保存数据 entities.SaveChanges(); return Json(new { ID = entity.ID }); #endregion }
public ActionResult GetPic() { var id = GetQueryString("ID"); FsFileInfo fileInfo = masterService.GetFileInfo(id, WeChatConfig.FileServerName); if (fileInfo != null) { ImageFormat imageFormat = ImageHelper.GetImageFormat(fileInfo.FileName.Split('.').Last()); return(new ImageActionResult(fileInfo.FileFullPath, imageFormat)); } return(new ImageActionResult(Server.MapPath(@"/CommonWebResource/RelateResource/image/photo.jpg"), ImageFormat.Jpeg)); }
// GET api/<controller>/5 public virtual HttpResponseMessage Get(string id) { FsFileInfo fileInfo = masterService.GetFileInfo(id, WeChatConfig.FileServerName); if (fileInfo != null) { //从图片中读取byte var imgByte = File.ReadAllBytes(fileInfo.FileFullPath); //从图片中读取流 var imgStream = new MemoryStream(File.ReadAllBytes(fileInfo.FileFullPath)); var resp = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(imgByte) //或者 //Content = new StreamContent(stream) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); return(resp); } return(new HttpResponseMessage(HttpStatusCode.NotFound)); }
public JsonResult AddFile() { var mpid = GetQueryString("MpID"); var filename = GetQueryString("FileName"); var wxFO = Formula.FormulaHelper.CreateFO<WxFO>(); foreach (var fn in filename.Split(',').Where(c => !string.IsNullOrEmpty(c))) { FsFileInfo fileInfo = masterService.GetFileInfo(fn, WeChatConfig.FileServerName); var entity = GetEntity<MpMediaVideo>(""); EntityCreateLogic(entity); entity.IsDelete = 0; entity.MpID = mpid; entity.Title = fileInfo.FileName.Substring(fileInfo.FileName.IndexOf('_') + 1); entity.FileID = fileInfo.FileName; var mediaid = wxFO.AddVideoFile(mpid, fileInfo.FileFullPath, entity.Title, ""); entity.MediaID = mediaid; entities.Set<MpMediaVideo>().Add(entity); } entities.SaveChanges(); return Json(JsonAjaxResult.Successful()); }