CKEditor SpringMvc 파일 업로드 구성

2878 단어
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("");
            out.println("window.parent.CKEDITOR.tools.callFunction("
                    + CKEditorFuncNum + ",'',"
                    + "' ( .jpg/.gif/.bmp/.png )');");
            out.println("");
            return;
        }
        if (upload.getSize() > 1024 * 1024 * 1) {
            out.println("");
            out.println("window.parent.CKEDITOR.tools.callFunction("
                    + CKEditorFuncNum + ",''," + "' 1M');");
            out.println("");
            return;
        }

        String imgUrl= paperApiService.uploadMath(upload,request);
        out.println("");
        out.println("window.parent.CKEDITOR.tools.callFunction("
                + CKEditorFuncNum + ",'" +imgUrl+ "','')");
        out.println("");

        return;
    }

좋은 웹페이지 즐겨찾기