Is it possible to identify file format while uploading Files using CommonsMultipartResolver (Spring 3)
I am trying to upload a PDF file from the browser using Spring's CommonsMultipartResolver as CommonsMultipartFile. Is it possi开发者_Go百科ble to validate the uploaded file is of PDF format only?
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 }
精彩评论