KindEditor Local Image Upload and upload failure in java

Source: Internet
Author: User

This code is the latest KindEditor 3.5.x to upload local images. The JSON format required for the KindEditor of the personal space to be revised by oschina is as follows:


{"Error": 0, "message": "...", "url": "/img/1111.gif "}
When the error value is 0, the upload is successful. You must specify the url value as the URL address after saving the image. If the error value is not 0, set the message value to the error message.


First, specify the URI of the upload process.

The Code is as follows: Copy code

KE. show ({
Id: 'ta _ blog_content ',
ResizeMode: 1,
ShadowMode: false,
AllowPreviewEmoticons: false,
UrlType: 'absolute ',
AllowUpload: true, // allows image uploading
ImageUploadJson: '/action/blog/upload_img' // the image processing URI uploaded by the server.
});

Image Upload Processing Method

The Code is as follows: Copy code

/**
* Upload images
* @ Param ctx
* @ Throws IOException
*/
@ Annotation. PostMethod
@ Annotation. JSONOutputEnabled
Public void upload_img (RequestContext ctx) throws IOException {
File imgFile = ctx. image ("imgFile ");
If (imgFile. length ()> MAX_IMG_SIZE ){
Ctx. output_json (
New String [] {"error", "message "},
New Object [] {1, ResourceUtils. getString ("error", "file_too_large", MAX_IMG_SIZE/1024 )}
);
Return;
}
String uri = new SimpleDateFormat ("yyyyMMdd"). format (new Date ())
+ "/IMG _"
+ RandomStringUtils. randomAlphanumeric (4)
+ '_'
+ String. valueOf (ctx. user (). getId ())
+ '.'
+ FilenameUtils. getExtension (imgFile. getName (). toLowerCase ();

Multimedia. saveImage (imgFile, img_path + uri, 0, 0 );
Ctx. output_json (new String [] {"error", "url"}, new Object [] {0, LinkTool. upload ("space/" + uri )});
}

Kindeditor uploads local images.

Why is a server error reported when kindeditor uploads a local image?

In demo. jsp:

The Code is as follows: Copy code

KE. show ({
Id: 'content1 ',
ImageUploadJson: '../jsp/upload_json.jsp ',
FileManagerJson: '../jsp/file_manager_json.jsp'. Why are two levels of folders returned? ("../" Indicates that the first-level folder is returned)
AllowFileManager: true,
AfterCreate: function (id ){
KE. event. ctrl (document, 13, function (){
KE. util. setData (id );
Document. forms ['example ']. submit ();
});
KE. event. ctrl (KE. g [id]. iframeDoc, 13, function (){
KE. util. setData (id );
Document. forms ['example ']. submit ();
});
}
});

It turns out that the JSON value of imageUploadJson is uploaded to the image folder under plugins. Therefore, to find upload_json.jsp, return to the root directory, that is, return two levels of menus. Now, we have finally solved the problem. We will start to transplant it to the article publishing system tomorrow, and finally we can go to bed.

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.