Check the uploaded file type, the uploaded file must be a picture or PDF.
1 2 3 4 5 6 7
// MultipartFile multipartFile StringcontentType= multipartFile.getContentType(); List<String> pdfFileType = ContentTypeEnum.PDF_FILE_TYPE.getMimeTypeList(); List<String> imageFileType = ContentTypeEnum.IMAGE_FILE_TYPE.getMimeTypeList(); if (!pdfFileType.contains(contentType) && !imageFileType.contains(contentType)) { return"The uploaded file only can be a picture or PDF."; }