百度UEditor自定义上传地址

栏目: 前端 · 发布时间: 6年前

内容简介:之前有个小朋友问我百度UEditor怎么自定义服务端上传地址, 正好也用过,现在做下笔记吧。在ue实例化的时候你服务端上传的请求地址赋值给serverUrl在上面自定义了服务端地址之后,我们刷新页面,ue实例化的时候会自动请求你的地址并且带着query参数,大概是这样:

之前有个小朋友问我百度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自定义上传地址


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Parsing Techniques

Parsing Techniques

Dick Grune、Ceriel J.H. Jacobs / Springer / 2010-2-12 / USD 109.00

This second edition of Grune and Jacobs' brilliant work presents new developments and discoveries that have been made in the field. Parsing, also referred to as syntax analysis, has been and continues......一起来看看 《Parsing Techniques》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具