public JsonResult ThumbImageAndInsertIntoDB() { string saveFullName = Request["saveFullName"]; string fileName = Request["title"]; string targetFilePath = Request["targetFilePath"]; string uploadFileType = Request["uploadFileType"]; string pid = Request["id"]; AttachmentsItemPostProperty p = new AttachmentsItemPostProperty() { SaveFullName = saveFullName, ServerPath = Server.MapPath("~/"), FileName = fileName, TargetFilePath = targetFilePath.Trim('/'), UploadFileType = uploadFileType, AppId = int.Parse(Request["appid"]), Description = Request["description"] == null ? string.Empty : Request["description"], VideoCoverSrc = Request["videoCoverSrc"] == null ? string.Empty : Request["videoCoverSrc"].Trim('/'), UserName = User.Identity.Name, ViewId = pid, }; SysAttachmentsItem itemView = _attachmentsItemService.ThumbImageAndInsertIntoDB(p); return(Json(new { Id = itemView.Id, AttachmentUrl = itemView.AttachmentUrl, AttachmentTitle = itemView.AttachmentTitle, Description = itemView.Description, Duration = itemView.Duration } , StrJsonTypeTextHtml)); }
private void GenerateNewsCoverThumbImage(string serverFileName, string realFileName, string targetFilePath) { AttachmentsItemPostProperty p = new AttachmentsItemPostProperty() { SaveFullName = serverFileName, ServerPath = Server.MapPath("~/"), TargetFilePath = targetFilePath.Trim('/'), UploadFileType = "image", AppId = int.Parse(Request["AppId"]), IsNewsCover = true }; _attachmentsItemService.ThumbImageAndInsertIntoDB(p); }
/// <summary> /// 消息内容存储到素材表 /// </summary> /// <param name="news"></param> /// <param name="uploadFileType"></param> /// <param name="strFileName"></param> private static void NewsToAttachments(NewsInfoView news, string uploadFileType, string strFileName) { IAttachmentsItemService _attachmentsItemService = EngineContext.Current.Resolve <IAttachmentsItemService>(); string strFullName = (HttpContext.Current == null ? HttpRuntime.AppDomainAppPath : HttpContext.Current.Request.PhysicalApplicationPath) + strFileName; AttachmentsItemPostProperty p = new AttachmentsItemPostProperty() { SaveFullName = Path.GetFileName(strFullName), ServerPath = HttpRuntime.AppDomainAppPath, FileName = news.NewsTitle, TargetFilePath = strFileName.Replace(Path.GetFileName(strFullName), "").Replace("//", "/").Trim('/'), UploadFileType = uploadFileType, AppId = news.AppId, Description = news.NewsComment, VideoCoverSrc = string.IsNullOrEmpty(news.ImageSrc) ? news.ImageContent : news.ImageSrc, UserName = _attachmentsItemService.Repository.LoginUserName,// User.Identity.Name, MediaId = news.MediaId, // MediaExpireTime= //ViewId = pid, }; SysAttachmentsItem itemView = _attachmentsItemService.ThumbImageAndInsertIntoDB(p); }
public SysAttachmentsItem ThumbImageAndInsertIntoDB(AttachmentsItemPostProperty p) { string saveFullName = p.SaveFullName; string fileName = p.FileName; string targetFilePath = p.TargetFilePath; string uploadFileType = p.UploadFileType; string saveDir = Path.Combine(p.ServerPath, targetFilePath); FileInfo fi = new FileInfo(Path.Combine(saveDir, saveFullName)); bool isUpdate = false; SysAttachmentsItem itemView = new SysAttachmentsItem(); if (!string.IsNullOrEmpty(p.ViewId) && !"null".Equals(p.ViewId.ToLower())) { itemView.Id = int.Parse(p.ViewId); isUpdate = true; } itemView.AppId = p.AppId; itemView.AttachmentTitle = fileName; itemView.Extension = fi.Extension; itemView.FileSize = fi.Length; itemView.CreateTime = DateTime.Now; itemView.UserId = p.UserName; itemView.UserName = p.UserName; itemView.AttachmentUrl = Path.Combine(targetFilePath, saveFullName).Replace("\\", "/"); itemView.MediaId = p.MediaId; if (uploadFileType.Contains("video")) { itemView.Type = (int)AttachmentsType.VIDEO; itemView.Description = p.Description; //itemView.Duration = GetDuration(Path.Combine(saveDir, saveFullName)); itemView.ThumbUrl = string.IsNullOrWhiteSpace(p.VideoCoverSrc) ? string.Empty : p.VideoCoverSrc.Replace("\\", "/"); } else if (uploadFileType.Contains("image")) { itemView.Type = (int)AttachmentsType.IMAGE; itemView.ThumbUrl = itemView.AttachmentUrl.Insert(itemView.AttachmentUrl.LastIndexOf('.'), "_T"); using (Stream fs = fi.Open(FileMode.Open)) { using (Image tempimage = Image.FromStream(fs, true)) { itemView.Width = tempimage.Width; //宽 itemView.Height = tempimage.Height; //高 } } //压缩逻辑已放入到Upload 时 //MakeThumbnailForUploadImage(p.ServerPath, targetFilePath, 1024, 768, "W", saveFullName, itemView); } else if (uploadFileType.Contains("audio") || uploadFileType.Equals("voice")) { itemView.Type = (int)AttachmentsType.AUDIO; //itemView.Duration = GetDuration(Path.Combine(saveDir, saveFullName)); } else { itemView.Description = fileName; itemView.Type = (int)AttachmentsType.FILE; } if (isUpdate) { this.Repository.Update(itemView); } else { this.Repository.Insert(itemView); } return(itemView); }