Springmvc文件上传监听

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
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);
 
  }
 
 }

标签: ssl

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:C#通过FtpWebResponse 编写GUI 简易 FTP客户端

下一篇: android 利用socket 发送Json数据demo