Using Spring's normal command bean binding or annotated method way of doing things requires you to know exactly the number of file uploads you expect at compile time.
Using Spring MVC 2.5:
@RequestMapping("/uploadFiles")
public String uploadFiles(HttpServletRequest request) {
if (request instanceof AbstractMultipartHttpServletRequest == false) {
throw new RuntimeException("Did not recieve an instance of AbstractMultipartHttpServletRequest.");
}
Map<String, MultipartFile> paramToFileMap = ((AbstractMultipartHttpServletRequest) request).getFileMap();
for (String fileParameter : paramToFileMap.keySet()) {
MultipartFile file = paramToFileMap.get(fileParameter);
// do something here...
}
return "uploadSuccess";
}
1 comment:
Thanks!
Post a Comment