spring mvc CommonsMultipartResolver 文件上传监听。
/** * 重写 parseRequest方法 监听 */ @Override protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException { System.out.println("MultipartParsingResult:--------------------------"+request); String encoding = determineEncoding(request); FileUpload fileUpload = prepareFileUpload(encoding); fileUpload.setFileSizeMax(-1); final HttpSession session = request.getSession(); fileUpload.setProgressListener(new ProgressListener() { @Override public void update(long pBytesRead, long pContentLength, int pItems) { try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } session.setAttribute("pBytesRead", pBytesRead); } }); try { List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request); return parseFileItems(fileItems, encoding); } catch (FileUploadBase.SizeLimitExceededException ex) { throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex); } catch (FileUploadException ex) { throw new MultipartException( "Could not parse multipart servlet request", ex); } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8018.html