如何不使用awsservice上传ckeditor文件

7jmck4yq  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(231)
<script>                             
CKEDITOR.replace( 'ckeditor', { 
     uploadUrl: "/image/drag",  // 이게 드래그 드롭을 위한 URL
     filebrowserUploadUrl: "/image"  // 파일업로드를 위한 URL
 } ); 

</script>

控制器

@RequestMapping(value = "/image/drag", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object handleFileUpload(@RequestParam("upload") MultipartFile uploadfile) {

        HashMap<String, Object> map = new HashMap<>();
        try {

            UploadFile uploadedFile = awsS3Service.upload(uploadfile);

            map.put("uploaded", 1);
            map.put("url", uploadedFile.getUrl());
            map.put("fileName", uploadedFile.getName());

            return map;
        } catch (Exception e) {
            map.put("uploaded", 0);
            map.put("error", "{'message': '" + e.getMessage() + "'}");
            return map;
        }     
    }    

    @PostMapping("/image")
    public void handleFileUpload(HttpServletRequest request, HttpServletResponse response, @RequestParam MultipartFile upload) {
        OutputStream out = null;
        PrintWriter printWriter = null;
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        try {
            String callback = request.getParameter("CKEditorFuncNum");

            UploadFile uploadedFile = awsS3Service.upload(upload);

            printWriter = response.getWriter();
            printWriter.println("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
                    + callback
                    + ",'"
                    + uploadedFile.getUrl()
                    + "','이미지를 업로드 하였습니다.'"
                    + ")</script>");
            printWriter.flush();            
        }catch(Exception e){
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (printWriter != null) {
                    printWriter.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

我使用的是java,spring框架。我不知道怎么把这个服务改成我的。

UploadFile uploadedFile = awsS3Service.upload(uploadfile);

谢谢您!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题