欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

UEditor编辑器上传图片开发流程_html/css_WEB-ITnose

程序员文章站 2022-05-17 13:07:05
...
在ueditor目录下找到uedior.config.js,找到如下三行:

1 ,imageUrl: "/controller.json" //图片上传提交后台对应的地址,路径固定为*/controller.*2 ,imagePath: "/ueditor/" //图片在服务器上的存储目录3 ,imageFieldName: "upload" //后台对应接收image的参数名

或者:

var ueditor = UE.getEditor('myEditor',{    imageUrl: "/servlet/UploadServlet", //图片上传提交后台对应的地址    imagePath: "/ueditor/",  //图片在服务器上的存储目录    imageFieldName: "upload"  //后台对应接收image的参数名});

注意:记得在uedior.config.js配置文件中把"serverUrl"注释掉

在/ueditor/_src/plugins/simpleupload.js文件中,把link = me.options.imageUrlPrefix + json.url; 改为link = getRootPath()+json.url;

最后配置服务器返回的数据格式,这需要这服务器端进行修改。对应于后台接收上传图片的那个controller,返回的格式需如下:

{'url':'60391393848223.jpg','title':'p1999637039.jpg','original':'p1999637039.jpg','state':'SUCCESS'}

注意:url用相对路径,这样就OK了。

//js获取项目根路径,如: http://localhost:8083/uimcardprjfunction getRootPath(){    //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp    var curWwwPath=window.document.location.href;    //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp    var pathName=window.document.location.pathname;    var pos=curWwwPath.indexOf(pathName);    //获取主机地址,如: http://localhost:8083    var localhostPaht=curWwwPath.substring(0,pos);    //获取带"/"的项目名,如:/uimcardprj    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);    //return localhostPaht + projectName;    return localhostPaht+"/";}