Kindeditor Editor Image batch upload using the upload plugin swfupload.swf, so the background upload file method return format should be jsonobject string Format (note).
Jsonobject format:
New Jsonobject (); Obj.put ("error", 0); // 0: Upload file successful, 1: Upload file failed
code example:
/*** File Upload public method * *@paramResponse *@paramRequest *@paramimgfile * Single file *@return */ PublicMap<string, object>uploadimg (httpservletresponse response, httpservletrequest request, Multipartfile imgfile) {respon Se.setcontenttype ("Text/plain;charset=utf-8"); Map<string, object> map =Maps.newhashmap (); //file save directory URLString Saveurl = "upload/img/"; //Maximum file size LongMaxSize = 102400000; if(Imgfile = =NULL) { returnReturnerrormap ("Please select File!")); } String imgfilefilename=Imgfile.getoriginalfilename (); String FileType= Imgfilefilename.substring (Imgfilefilename.lastindexof (".") + 1). toLowerCase ();//File Typemap<string, string> filetypemap =Maps.newhashmap (); Filetypemap.put ("Image", "Gif,jpg,jpeg,png,bmp"); if(Filetypemap.containskey (FileType)) {returnReturnerrormap ("Upload file extension [" + FileType + "] is an extension that is not allowed. "); } if(Imgfile.getsize () >maxSize) { returnReturnerrormap ("[" + Imgfilefilename + "] exceeds a single file size limit, file size [" + imgfile.getsize () + "], limited to [" + MaxSize + "]"); } String NewFileName= System.currenttimemillis () + "." + FileType;//Re-name Try{fileutils.copyinputstreamtofile (Imgfile.getinputstream (),NewFile (Saveurl, NewFileName));//Generating Files returnmap; } Catch(Exception e) {returnReturnerrormap ("Image upload failed"); } } /** * * @paramResponse *@paramRequest *@paramImgfiles * Multiple Files *@return */@RequestMapping ("/upload") Public@ResponseBody String Uploadimgs (httpservletresponse response, HttpServletRequest request, @RequestParam ( c0>"Imgfiles") multipartfile[] imgfiles) {Response.setcontenttype ("Text/plain;charset=utf-8"); String URL= ""; Jsonobject obj=NewJsonobject ();//JSON format must be returned otherwise swfupload.swf cannot parse the error Try { for(Multipartfile myfile:imgfiles) {Map Imgpath= uploadimg (response, request, myFile);//Upload Method if(Imgpath.get ("error"). Equals ("0")) ) {URL+ = Imgpath + ","; }} obj.put ("Error", 0);//Upload Successful if(Url.length () > 0) {Obj.put ("url", url.substring (0, Url.length ()-1));//upload successful path to all picture addresses}Else{obj.put ("url", URL); } } Catch(Exception e) {e.printstacktrace (); Obj.put ("Error", 1);//Upload failedObj.put ("url", URL); } returnobj.tostring (); } /*** ERROR message * *@parammessage *@return */ PrivateMap<string, object>returnerrormap (String message) {Map<string, object> map =Maps.newhashmap (); Map.put ("Error", 1); Map.put ("Message", message); returnmap; }
jquery Calls:
$(function() {Kindeditor.ready (function(K) {varEditor1 = K.create ("Textarea[name= ' content_body ']", {uploadjson:‘.. /kindeditor/upload ',//background Upload call method address, return JSON formatAftercreate:function() { varSelf = This; }, Afterblur:function(){ This. sync ();} }); }); });
:
Kindeditor Image Batch Upload