List<FileItem> fileItems=sfu.parseRequest(request); fileitems 为,空

最近在使用wangEditor做上传文件的功能

但是有一点非常的让人难受,我在上传文件的时候每个方面代码都是没有问题的

比如前台:

	var editor = new wangEditor('#txtDiv');
	editor.customConfig.uploadImgServer = serviceUrl+'/Shopping/filecontroller/uploadfile';
	editor.customConfig.uploadImgFileName = 'myFileName';
	editor.customConfig.showLinkImg = false;
	editor.create();

这样我上传定义了上传文件的接口路径,后台我使用的是SpringMVC这个框架,接口我是这样写的:

	@RequestMapping(value = "/uploadfile")
	public void uploadFile(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		log.info("-------------------开始调用上传文件uploadfile接口-------------------");
		String path = this.getClass().getClassLoader().getResource("/").getPath();
		int index = path.indexOf("Shopping");
		path = path.substring(0, index + "Shopping".length()) + "/WebContent/resources/upload/";
        DiskFileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload sfu = new ServletFileUpload(factory);
        sfu.setHeaderEncoding("UTF-8"); // 处理中文问题
        sfu.setSizeMax(1024 * 1024); // 限制文件大小
        String fileName="";
        try {
        	 List<FileItem> fileItems=sfu.parseRequest(request);
        	 for(FileItem item:fileItems){
        		 fileName=UUID.randomUUID().toString()+item.getFieldName().substring(item.getFieldName().lastIndexOf('.'), item.getFieldName().length());
        		 item.write(new File(path+"//"+fileName));
        	 }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //获取图片url地址
        String imgUrl = "resources/upload/"+fileName;
        response.setContentType("text/text;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print(imgUrl);
        out.flush();
        out.close();
    	log.info("-------------------结束调用上传文件uploadfile接口-------------------");
	}

看样子每个方面都很好,但是有点问题是在上传文件的时候后台获取不到文件,我打断点看了看发现的是:

zh这个地方获取到的list一直是空,我不明白为什么,也一直在研究为甚为空,我想来想可能和我的SpringMVC框架有关系,因为我们在配置文件里面有这样的一段,所以把我的文件给拦截掉了


当我把这一段注释掉了之后,发现上传文件正常了,如果你使用wangEditor的时候也在上传文件遇到了问题,看看是不是因为配置文件的问题,希望对你有所帮助!

猜你喜欢

转载自blog.csdn.net/datouniao1/article/details/80509455