kindeditor java 上传图片_java中KindEditor本地图片上传与上传失败问题
此代碼是最新版的 KindEditor 3.5.x 實現本地圖片上傳的方法,用于oschina即將改版的個人空間
KindEditor 要求的JSON格式如下:
{"error":0,"message":".....","url":"/img/1111.gif"}
其中當error值為0時表示上傳成功,需要指定url值為圖片保存后的URL地址,如果error值不為0,則設置message值為錯誤提示信息
首先指定上傳處理的URI
代碼如下
復制代碼
KE.show({
id : 'ta_blog_content',
resizeMode : 1,
shadowMode : false,
allowPreviewEmoticons : false,
urlType : 'absolute',
allowUpload : true, //允許上傳圖片
imageUploadJson : '/action/blog/upload_img' //服務端上傳圖片處理URI
});
圖片上傳處理方法
代碼如下
復制代碼
/**
* 圖片上傳
* @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上傳本地圖片的問題 .
現kindeditor上傳本地圖片時,為什么出現服務器錯誤
原來demo.jsp里的:
代碼如下
復制代碼
KE.show({
id : 'content1',
imageUploadJson : '../../jsp/upload_json.jsp',
fileManagerJson : '../../jsp/file_manager_json.jsp', 為什么要返回兩級文件夾呢?(”../“代表返回一級文件夾)
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();
});
}
});
原來是因為imageUploadJson 這個JSON值是傳到plugins下的image文件夾里。于是,要找到upload_json.jsp,則要返回到根目錄,即返回兩層菜單。好了,終于解決了,明天就開始移植到文章發布系統了,終于可以睡了
總結
以上是生活随笔為你收集整理的kindeditor java 上传图片_java中KindEditor本地图片上传与上传失败问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql的默认sid_默认实例(SID
- 下一篇: java关闭inputstream_关闭