ueditor-Version: 1.4.3
Die Dateiempfangsverarbeitung ist im Controller geschrieben und verwendet nicht das vom Editor bereitgestellte Ashx, um hochgeladene Dateien zu empfangen.
Instanziierung des Editors, da Erforderliche Bearbeitung verschiedener Seiten. Bei der Instanziierung werden die Konfigurationsparameter übergeben:
var editor = new baidu.editor.ui.Editor({ toolbars: [["date", "time", "horizontal", "anchor", "spechars", "blockquote", "pagebreak", "bold", "italic", "underline", "strikethrough", "forecolor", "backcolor", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "directionalityltr", "directionalityrtl", "indent", "removeformat", "autotypeset", "formatmatch", "pasteplain"], ["customstyle", "paragraph", "rowspacingbottom", "rowspacingtop", "lineheight", "fontfamily", "fontsize", "imagenone", "inserttable", "deletetable", "mergeright", "mergedown", "splittorows"], ["splittocols", "splittocells", "mergecells", "insertcol", "insertrow", "deletecol", "deleterow", "insertparagraphbeforetable", "fullscreen", "source", "undo", "redo", "insertunorderedlist", "insertorderedlist", "unlink", "link", "cleardoc", "selectall", "searchreplace", "separate", 'simpleupload'] ], serverUrl: '../UploadImage' }); editor.render("Content");
serverUrl ist die Upload-Adresse, die die Aktion im Controller darstellt. Die beiden Doppelpunkte können nicht entfernt werden . Beispiel:
noCache=1477646749295. Daher ist es richtig, serverUrl in „../UploadImage“ zu ändern.
Aktionscode:
public ActionResult UploadImage() { var action = Request["action"]; var json = ""; if (action == "config") { json =@"{""imageActionName"":""UploadImage"",""imageFieldName"": ""upfile"",""imageCompressEnable"":""true"",""imageCompressBorder"": 1600,""imageInsertAlign"": ""none"",""imageUrlPrefix"": """",""imageAllowFiles"": ["".png"", "".jpg"", "".jpeg"", "".gif"", "".bmp""]}"; } else { var file= Request.Files["upfile"]; var relativePath = AppConfig.GetAppSettingsValue("CustomizeProductMaskImageRelativePath"); var newFileName = string.Concat(DateTime.Now.ToString("yy-MM-dd"), Path.GetExtension(file.FileName)); var savePath = Server.MapPath(relativePath); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } relativePath = Path.Combine(relativePath, newFileName); // 合成目标文件路径 var srcFileName = FilePath.CombinePath(savePath, newFileName); // 保存图片 file.SaveAs(srcFileName); var tvcMallImageUrl = ""; // 上传图片到外网服务器 tvcMallImageUrl = ""; json = json + "{\"url\":\"" + tvcMallImageUrl+"\","; json = json + "\"state\":\"SUCCESS\"}"; } return new ContentResult { ContentEncoding = Encoding.UTF8, ContentType = "application/json", Content = json }; }
Es gibt eine Gefahr beim Bearbeiten und Empfangen des zurückgegebenen JSON, wenn der zurückgegebene JSON < ist 🎜>
"{\"imageActionName\":\"UploadImage\",\"imageFieldName\": \"upfile\",\"imageCompressEnable\":\"true\",\"imageCompressBorder\": 1600,\"imageInsertAlign\": \"none\",\"imageUrlPrefix\": \"\",\"imageAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"]}"
{"imageActionName":"UploadImage","imageFieldName": "upfile","imageCompressEnable":"true","imageCompressBorder": 1600,"imageInsertAlign": "none","imageUrlPrefix": "","imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"]}
return Content(json, "application/json", Encoding.UTF8); return Json(json,"application/json",Encoding.UTF8,JsonRequestBehavior.AllowGet); return JavaScript(json); return new JsonResult() {ContentEncoding = Encoding.UTF8, ContentType = "application/json", Data = json,JsonRequestBehavior = JsonRequestBehavior.AllowGet}; return new ContentResult { ContentEncoding = Encoding.UTF8, ContentType = "application/json", Content = json };
{"imageActionName":"UploadImage","imageFieldName": "upfile","imageCompressEnable":"true","imageCompressBorder": 1600,"imageInsertAlign": "none","imageUrlPrefix": "","imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"]}
"{\"imageActionName\":\"UploadImage\",\"imageFieldName\": \"upfile\",\"imageCompressEnable\":\"true\",\"imageCompressBorder\": 1600,\"imageInsertAlign\": \"none\",\"imageUrlPrefix\": \"\",\"imageAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"]}"