Replace the URL of the upload and preview image in the JSP
Note the first sentence, note the relative URL of the item
Return '/sirdifoa/kentra/file/uploadimage.do ';
if (UE. editor.prototype._bkgetactionurl == undefined) UE. Editor.prototype._bkgetactionurl = ue. Editor.prototype.getactionurl; ue. Editor.prototype.getactionurl = function (Action) { //judgment path Here is the action name in the config.json set to perform the upload if (action == ' Uploadimage ') { return '/sirdifoa/kentra/file/uploadimage.do '; } else if (action == ' Uploadvideo ') { return '; } else { return this._bkgetactionurl.call (This, action); } }
Customize the way you upload and preview your pictures.
@RequestMapping ("/uploadimage") @ResponseBody // here upfile is the form name submitted in Config.json image public map< String, string> uploadimage (@RequestParam ("Upfile") commonsmultipartfile upfile, Httpservletrequest request) throws IOException {// file original name string filename = upfile.getoriginalfilename ();// to avoid repetitive simple processing string nowname = new date (). GetTime () + "_" + fileName;if (!upfile.isempty ()) {string ueditorimagepath = propertyutil.readvalue (Const.ueditorimagepath); Simpledateformat simpledateformat = new simpledateformat ("YyyyMMdd"); String formatday = simpledateformat.format (New date ());// upload location path string path0 = ueditorImagePath + "/" +formatday+ "/" + nowname;// new file by Path Java.io.File newfile = new java.io.file (path0); java.io.file newfile1 = new java.iO.file (ueditorimagepath+ "/" +formatday);if (!newfile1.exists ()) {boolean mkdir = newfile1.mkdirs ();} Copy filecopyutils.copy (Upfile.getbytes (), newfile);} Return result information (Ueditor required) map<string, string> map = new hashmap<string, String> ();// whether the upload succeeded Map.put ("state", "SUCCESS");// now file name Map.put ("title", nowname);// File original name Map.put ("original", filename);// file type .+ suffix map.put ("type", filename.substring ( Upfile.getoriginalfilename (). LastIndexOf (".")); / file path map.put ("url", "/kentra/file/getimage.do?imgname=" +nowname);// File Size (bytes) map.put ("Size", upfile.getsize () + ""); return map;} /** * * Read file * */@RequestMapping ("/getimage") public void Readimg (String imgname, httpservletresponse response) throws exception {// Sets the return type of the file Response.setcontenttype ("image/*"); SimpleDateFormat simpledateformat = new simpledateformat ("YyyyMMdd"); String formatday = simpledateformat.format (New date ());// file path (under Windows is \\,linux Yes//, Must be an absolute path) String imgpath = propertyutil.readvalue (Const.ueditorimagepath) + "/" + The file class is used in the formatday+ "/" +imgname;// java to represent a java.io.file newfile = new java.io.file ( Imgpath);// Tests if the file path exists (that is, if the file exists) if (!newfile.exists ()) {return;} fileutils.readfiletobytearray (File file) converts a file into a byte array to return Response.getoutputstream (). Write ( Fileutils.readfiletobytearray (newFile))// java when using a stream, there is a buffer that sends the data in a way that it thinks is more efficient:// the data to be sent to the buffer. When the buffer fills up and then sends the past one time, instead of sending the .// separately and flush () means that the data in the buffer is forced to be sent out without waiting for the buffer to be full. Response.getoutputstream (). Flush (); Response.getoutputstream (). Close ();}
Add a path prefix to the Config.json:
/* Upload Picture Configuration item */"Imageactionname": "Uploadimage",/* Execute the action name of the upload picture */"Imagefieldname": "Upfile",/* submitted picture form name */ "Imagemaxsize": 20480000,/* Upload size limit, Unit B */"imageallowfiles": [". png", ". jpg", ". jpeg", ". gif", ". bmp"],/* Upload picture format display * /"imagecompressenable": true,/* whether to compress the picture, the default is True */"Imagecompressborder": 1600,/* picture compression longest edge limit */"Imageinsertalig N ":" None ",/* Insert Picture floating way */" Imageurlprefix ":"/sirdifoa ",/* ============== picture access path prefix ==================*/
This article is from the "Jianbo" blog, make sure to keep this source http://jianboli.blog.51cto.com/12075002/1969542
Baidu ueditor--Custom upload file path and read file