Commons-fileupload upload.parseRequest(request)size()为0

时间:2018-08-12 03:42:00

标签: java apache-commons apache-commons-fileupload

我直接在Project中使用Commons-fileupload。但是

        HttpServletRequest request = WebcUtils.getRequest(context);
        HttpServletResponse response = WebcUtils.getResponse(context);
        logger.info("request parameter: " + request.getParameter("chkDate"));

        if (!ServletFileUpload.isMultipartContent(request)) {
            ResponseUtil.sendResponseData(response, new ResultJson<String>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), null).toJsonString());
        }
        DiskFileItemFactory factory = new DiskFileItemFactory();

        factory.setSizeThreshold(MEMORY_THRESHOLD);

        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setFileSizeMax(MAX_FILE_SIZE);
        upload.setSizeMax(MAX_REQUEST_SIZE);
        upload.setHeaderEncoding("UTF-8");
        String uploadPath = UPLOAD_DIRECTORY;
        File uploadDir = new File(uploadPath);
        if (!uploadDir.exists()) {
            uploadDir.mkdir();
        }
        List<FileItem> formItems = upload.parseRequest(request);
        System.out.println("size is : " + formItems.size());

,但最后一行formItems.size()返回0。 这是我的要求(我使用邮递员进行测试): enter image description here

我认为我的请求没有错误。但是我不知道为什么大小为0?

编辑: l调试commmons-fileupload的源代码,我在MultipartStream.skipPreamble()中发现了异常:

org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly

0 个答案:

没有答案