コード例 #1
0
        /// <summary>
        /// 上传并保存微信图片素材
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <JsonResult> SaveAndUpdate(MpMediaImageDto input)
        {
            MpMediaImageDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var profilePictureFile = Request.Form.Files.First();
                Logger.Info("开始上传文件");
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                Logger.Info("文件大小:" + fileBytes.Length);
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.image.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
                input.MediaID = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.image);
            }

            if (input.Id == 0)
            {
                result = await _mpMediaImageAppService.Create(input);
            }
            else
            {
                result = await _mpMediaImageAppService.Update(input);
            }
            return(Json(result));
        }
コード例 #2
0
 public CreateOrEditMpMediaImageViewModel(MpMediaImageDto output)
 {
     output.MapTo(this);
 }