Spring mvc 上传文件,报The current request is not a multipart request

public UploadResponse upload(@RequestParam(required = false) MultipartFile zipFile, String token){...}

可见zipFile是要求为可传可不传的。

zipFile有文件上传,是成功的,如果zipFile是null的,就报:org.springframework.web.multipart.MultipartException: The current request is not a multipart request

解决方法

public UploadResponse upload(HttpServletRequest request, String token){

MultipartFile pFile = null;
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
if(multipartResolver.isMultipart(request)){
    MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;  
    pFile = multiRequest.getFileMap().get("pFile");
}

}

参考:http://www.cnblogs.com/dongying/p/4388464.html

你可能感兴趣的:(Android,Spring)