我正在尝试使用Spring的CommonsMultipartResolver作为CommonsMultipartFile从浏览器上传PDF文件。是否可以验证上传的文件仅为PDF格式?
答案 0 :(得分:0)
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Iterator it = (Iterator) multipartRequest.getFileNames(); String fileName = it.next(); MultipartFile file = multipartRequest.getFile(fileName); String ext = fileName.substring(fileName.lastIndexOf(".")); if(ext.equalsIgnoreCase(".pdf")) { //do something } else { //do something }