文件上传 WebUploader

WebUpload

<%@ page contentType="text/html;charset=UTF-8" language="java" %>



    
    Document
    
    



选择文件

    servlet

    package com.kaishengit.web;
    
    
    @WebServlet("/qiniu")
    public class QiniuServlet extends BaseServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String ak = "G3jWeQ4OOxUwAQJumftrS_jcAej9uBQLn1-oCoHD";
            String sk = "fmiPh7SZ_UvRWRsntAihdOS67Pin9jeeNYR3aRBv";
            String bucketName = "demo22";
    
            Auth auth = Auth.create(ak,sk);
            //计算上传文件的Token
            StringMap map = new StringMap();
            map.put("returnUrl","http://localhost:8080/qiniucallback");
    
            String token = auth.uploadToken(bucketName,null,3600,map);
    
            req.setAttribute("token",token);
            req.getRequestDispatcher("qiniu.jsp").forward(req,resp);
    
        }
    }
    
    
    

    WebUploader 和 七牛云 整合

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    
    
    
        
        Document
        
        
    
    
    
    
    选择文件

    servlet

    package com.kaishengit.web;
    
    @WebServlet("/qiniu2")
    public class QiniuServlet2 extends BaseServlet {
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            String ak = "inOypU6O-rKyxyN22Z7Cq1uHMdc4YmhjE1GfJh7L";
            String sk = "l342cQNqBu2GSVUmhz_2by7yBPKJ7foeDH_0tN5r";
            String bucketName = "demo22";
    
            Auth auth = Auth.create(ak,sk);
    
            //获取Session中的对象
           /* HttpSession session = req.getSession();
            User user = (User) session.getAttribute("user");
            int id = user.getId();*/
    
    
            String token = auth.uploadToken(bucketName);
    
            req.setAttribute("id",11223);
            req.setAttribute("token",token);
            req.getRequestDispatcher("uploer_qiniu.jsp").forward(req,resp);
    
    
        }
    }
    
    

    文本编辑器

    simditor
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    
    
    
        
        Document
        
        
    
    
    
        

    servlet

    package com.kaishengit.web;
    
    
    @WebServlet("/wysiwyg")
    public class WysiwygServlet extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String ak = "inOypU6O-rKyxyN22Z7Cq1uHMdc4YmhjE1GfJh7L";
            String sk = "l342cQNqBu2GSVUmhz_2by7yBPKJ7foeDH_0tN5r";
            String bucketName = "demo22";
    
            Auth auth = Auth.create(ak,sk);
    
            String returnBody = "{\"success\":true,\"file_path\":\"http://ohwnpkfcx.bkt.clouddn.com/${key}\"}";
    
            StringMap map = new StringMap();
            map.put("returnBody",returnBody);
    
            String token = auth.uploadToken(bucketName,null,3600,map);
    
            req.setAttribute("token",token);
            req.getRequestDispatcher("wysiwyg.jsp").forward(req,resp);
    
    
    
        }
    }
    
    

    你可能感兴趣的:(文件上传 WebUploader)