开发者

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜