How to check a uploaded file whether it is an image or other file?
I’m assuming that you’re running this in a servlet context. If it’s affordable to check the content type based on just the file extension, then use ServletContext#getMimeType() to get the mime type (content type). Just check if it starts with image/. String fileName = uploadedFile.getFileName(); String mimeType = getServletContext().getMimeType(fileName); if (mimeType.startsWith(“image/”)) { // It’s an …