I get a File via a HTTP-Upload and need to be sure its a pdf-file. Programing Language is Python, but this should not matter.
I thought of the following solutions:
Check if the first bytes of the string are "%PDF". This is not a good check but prevents the use from uploading other files accidentally.
Try the libmagic (the "file" command on the bash uses it). This does exactly the same check as 1.
Take a lib and try to read the page-count out of the file. If the lib is able to read a pagecount it should be a valid pdf. Problem: I dont know a lib for python which can do this
So anybody got any solutions for a lib or another trick?
Thanks