前台ajax 从后台获取文件流上传文件

前台ajax请求

前台ajax 从后台获取文件流上传文件

后台接收请求  读取某个文件夹下的文件

@ResponseBody
    public void getPic(HttpServletRequest request,HttpServletResponse response,@RequestParam("path") String path) throws IOException {
        path = path.replace("/", "\\");
        logger.info("--file dir---"+path);
        System.out.println("--file dir---"+path);
        //path = "C:/Users/Administrator/UsersAdministratorDocumentsAthenaEyeImagesimage.pdf";
        response.setStatus(HttpServletResponse.SC_OK);  
        //response.setContentType("application/pdf;charset=UTF-8");  
        BufferedInputStream input = new BufferedInputStream(new FileInputStream(path));  
        byte buffBytes[] = new byte[1024];  
        OutputStream out = null;
        try {
            out = response.getOutputStream();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
        int read = 0;    
        while ((read = input.read(buffBytes)) != -1) {    
            out.write(buffBytes, 0, read);    
        }  
        out.flush();    
        out.close();
    }

 

从后台获取到文件流后 前台装换成 字节数组 再上传到服务器

前台ajax 从后台获取文件流上传文件