美文网首页
CKEditor SpringMvc文件上传配置

CKEditor SpringMvc文件上传配置

作者: DamagedBoy | 来源:发表于2017-06-29 23:52 被阅读0次

config.js文件配置:

CKEDITOR.editorConfig = function( config ) {
    config.language = 'zh-cn';
    config.toolbar_MyBasic = [
        [ 'Bold', 'Italic','Underline', 'Strike'],
        ['FontSize','Image', 'helloworld']
    ];
    config.filebrowserImageUploadUrl='/api/paper/uploadMath?';
    config.extraPlugins += (config.extraPlugins ? ',helloworld' : 'helloworld');
    config.removePlugins = 'elementspath';
    config.resize_enabled = false;
    config.skin = 'moono-lisa';
};

Java代码:

 @RequestMapping("/uploadMath")
    public void uploadMath(@RequestParam MultipartFile upload,
                             HttpServletRequest request, HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        String CKEditorFuncNum = request.getParameter("CKEditorFuncNum");
        String fileName = upload.getOriginalFilename();
        String uploadContentType = upload.getContentType();
        String expandedName = "";
        if (uploadContentType.equals("image/pjpeg")
                || uploadContentType.equals("image/jpeg")) {
// IE6上传jpg图片的headimageContentType是image/pjpeg,而IE9以及火狐上传的jpg图片是image/jpeg
            expandedName = ".jpg";
        } else if (uploadContentType.equals("image/png")
                || uploadContentType.equals("image/x-png")) {
// IE6上传的png图片的headimageContentType是"image/x-png"
            expandedName = ".png";
        } else if (uploadContentType.equals("image/gif")) {
            expandedName = ".gif";
        } else if (uploadContentType.equals("image/bmp")) {
            expandedName = ".bmp";
        } else {
            out.println("<script type=\"text/javascript\">");
            out.println("window.parent.CKEDITOR.tools.callFunction("
                    + CKEditorFuncNum + ",'',"
                    + "'文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)');");
            out.println("</script>");
            return;
        }
        if (upload.getSize() > 1024 * 1024 * 1) {
            out.println("<script type=\"text/javascript\">");
            out.println("window.parent.CKEDITOR.tools.callFunction("
                    + CKEditorFuncNum + ",''," + "'文件大小不得大于1M');");
            out.println("</script>");
            return;
        }

        String imgUrl= paperApiService.uploadMath(upload,request);
        out.println("<script type=\"text/javascript\">");
        out.println("window.parent.CKEDITOR.tools.callFunction("
                + CKEditorFuncNum + ",'" +imgUrl+ "','')");
        out.println("</script>");

        return;
    }

相关文章

网友评论

      本文标题:CKEditor SpringMvc文件上传配置

      本文链接:https://www.haomeiwen.com/subject/lttbcxtx.html