Kindeditor Image Batch Upload

Source: Internet
Author: User

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

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.