I have a backend service in Java which uploads a file to the server.But I seems that some unwanted file types are being uploaded.
For e.g.: If I have a foo.jpg file and rename it to foo.pdf
then it gets uploaded .How can I check the actual content of foo.pdf
Below is the code that I am using
for (Part part : request.getParts()) {
if (part.getName().startsWith("file")) {
String filename = part.getHeader("content-disposition");
filename = filename.replaceFirst("(?i)^.*filename=\"([^\"]+)\".*$", "$1");
String fileType = part.getContentType();
DocumentUpload documentUpload = new DocumentUpload();
documentUpload.setFilename(filename);
documentUpload.setFileType(fileType);
documentUpload.setPayload(part.getInputStream());
response = documentService.save(documentUpload, uriInfo);
break;
}
}