之前有个小朋友问我百度UEditor怎么自定义服务端上传地址, 正好也用过,现在做下笔记吧。

在ue实例化的时候你服务端上传的请求地址赋值给serverUrl

var ue;ue = UE.getEditor('editor', {    toolbars: [        //这个是工具栏配置,自己定义和今天主题无关        [            'fullscreen', 'source', '|', 'undo', 'redo', '|',            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript',             'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|',            'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',            'directionalityltr', 'directionalityrtl', 'indent', '|',            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',            'simpleupload', '|', 'pagebreak', 'template', 'background', '|',            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol',             'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows',             'splittocols', 'charts', '|',            'preview'        ]    ],    serverUrl: 'http://your-server-address'  //这里是你服务端上传的请求地址}); 

在上面自定义了服务端地址之后,我们刷新页面,ue实例化的时候会自动请求你的地址并且带着query参数,大概是这样:http://your-server-address?ac...。这是ue实例化会请求配置文件,简单点你可以直接返回ue插件文件夹中ueditor/1.4.3.3/php/config.json的内容就可以了。当然了具体配置你是可以自己按自己需求改动。

接下来上传图片,随便上传一张图片,会发现ue的请求地址是http://your-server-address?ac...。这样是不是恍然大悟:

action参数是config,你就给他返回配置内容;action参数是uploadimage就是图片上传,你就保存图片文件,返回成功或者失败的结果。

上传结果返回格式是这样的:

失败的情况

{    "state": "Failed",    "msg": "error msg"}

成功的情况:

{

"state": "SUCCESS","msg": "ok","original": "aaa.jpg",    //图片源文件名"type": ".jpg",        //图片后缀"size": 10240000,    //图片大小"title": "aaa",        //图片img标签上的属性title"url": "/upload/fsf3r.jpg"            //图片上传之后的url

}
好了就这样

原为连接:
百度ueditor自定义上传地址

更多知识分享,请扫码关注: