开发者

Is it possible to identify file format while uploading Files using CommonsMultipartResolver (Spring 3)

开发者 https://www.devze.com 2023-03-17 02:12 出处:网络
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?

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

精彩评论

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