public IActionResult MDEditor_API() { string action = GetParam("action"); string result = ""; switch (action) { case "down": { string content = RequestEx["content"]; Stream sm = IOHelper.BytesToStream(Encoding.UTF8.GetBytes(content)); //var memi = provider.Mappings[fileExt]; return(File(sm, "text/plain", "content.md")); } case "upload": //上传图片 { var file = Request.Form.Files["editormd-image-file"]; string vpath = ZLHelper.GetUploadDir_Anony("content", "md"); string fname = function.GetRandomString(10) + "." + GetImgExt(file.FileName); string url = SafeC.SaveFile(vpath, fname, file.OpenReadStream(), (int)file.Length); result = JsonHelper.GetJson( new string[] { "success", "message", "url" }, new string[] { "1", "上传成功", url }); } break; } return(Content(result)); }
//上传base64图片 public IActionResult Base64() { string base64str = Request.Form["base64"];//上传的base64字符串 string action = Request.Form["action"]; string uploadPath = ""; string saveName = function.GetRandomString(6) + ".jpg"; string result = ""; M_UserInfo mu = buser.GetLogin(); try { if (!mu.IsNull) { uploadPath = ZLHelper.GetUploadDir_User(mu, "dai"); } else if (adminMod != null) { uploadPath = ZLHelper.GetUploadDir_Admin(adminMod, "dai"); } else //Not Login { uploadPath = ZLHelper.GetUploadDir_Anony("dai"); } ImgHelper imghelper = new ImgHelper(); imghelper.Base64ToImg(uploadPath + saveName, base64str); result = uploadPath + saveName; return(Content(result)); } catch (Exception ex) { ZLLog.L(ZLEnum.Log.fileup, new M_Log() { Source = Request.RawUrl(), Message = "上传失败|文件名:" + uploadPath + saveName + "|" + "原因:" + ex.Message }); return(Content(Failed.ToString())); } }