Umeditor Upload image relative path settings and save

Source: Internet
Author: User

This article is only dedicated to the implementation of Baidu Rich text editor, want to set the relative path and save to the database, easy to later project migration.

The version used is 1.2.3, which is suitable for cross-click on images and drag-and-drop functions.

        Save the settings for the relative address of the picture
1. Modify the Uploader.java Getphysicalpath () method to set the return address
2. Please modify the relative address in imageup.jsp result
3. Modify Getallpic () in image.js to set SRC, _src return value

1, modify the background code Uploader.java

    /*** Get physical path based on incoming virtual path * *@paramPath *@return     */    Privatestring Getphysicalpath (string path) {//Original: Upload the file in the request path (Baidu Editor) on the first level//String Servletpath = This.request.getServletPath ();//String Realpath = this.request.getSession (). GE Tservletcontext ()//. Getrealpath (Servletpath);//return new File (Realpath). GetParent () + "/" +path; //modified version: Upload files under WebAppString ServletContext = This. Request.getsession (). Getservletcontext (). Getrealpath (""); return NewFile (ServletContext). GetParent () + "/" +path; }

2, modify the imageup.jsp

    //  String result = "{\" name\ ": \" "+ up.getfilename () +" \ ", \" originalname\ ": \" "+ up.getoriginalname () +" \ ", \" size\ ":" + Up.getsize () + ", \" state\ ": \" "+ up.getstate () +" \ ", \" type\ ": \" "+ up.gettype () +" \ ", \" url\ ": \" "+ up.geturl () +" \ "}"; /c2>    // modified version: According to imageup.jsp relative position to modify, here the picture is placed under the WebApp (different position self-modification)    String result = "{\" name\ ": \" " + up.getfilename () + "\", \ "originalname\": \ "" + up.getoriginalname () + "\", \ "size\": "+ up.getsize () +", \ "state\": \ "" + U P.getstate () + "\", \ "type\": \ "" + up.gettype () + "\", \ "url\": \ "" + Pathpre + up.geturl () + "\"} ";

3, modify the image.js

Getallpic:function(SEL, $w, editor) {varme = This, arr=[], $imgs=$ (SEL, $w); $.each ($imgs,function(Index, node) {$ (node). Removeattr ("width"). Removeattr ("height"));//if (Node.width > Editor.options.initialFrameWidth) {//Me.scale (node, editor.options.initialFrameWidth-//parseint ($ (editor.body). CSS ("Padding-left"))-//parseint ($ (editor.body). CSS ("Padding-right")));//                }                //Modified version: set to relative path (modify as needed)                varSrcfixed =node.src; Srcfixed= Srcfixed.slice (Srcfixed.indexof (' upload '))); Srcfixed= ".. /.. /.. /.. /.. /" +srcfixed; returnArr.push ({//_src:node.src,                    //SRC:NODE.SR_src:srcfixed, src:srcfixed});            }); returnarr; },

In this way, the data stored in the database is the relative address, regardless of IP, domain name.

Umeditor Upload image relative path settings and save

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.