百度UEditor自定义上传地址

以前有个小朋友问我百度UEditor怎么自定义服务端上传地址, 正好也用过,如今作下笔记吧。php

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

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的内容就能够了。固然了具体配置你是能够本身按本身需求改动。json

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

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

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

失败的状况spa

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

成功的状况:插件

{code

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

}
好了就这样orm

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

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

v2-f6f42f396ad0c97a92b315863ee1e718_hd.jpg

相关文章
相关标签/搜索