Checking file type with django form: 'application/octet-stream' issue
You should not rely on the MIME type provided, but rather the MIME type discovered from the first few bytes of the file itself.
This will help eliminate the generic MIME type issue.
The problem with this approach is that it will usually rely on some third party tool (for example the file command commonly found on Linux systems is great; use it with -b --mime - and pass in the first few bytes of your file to have it give you the mime type).
The other option you have is to accept the file, and try to validate it by opening it with a library.
So if pypdf cannot open the file, and the built-in zip module cannot open the file, and rarfile cannot open the file - its most likely something that you don't want to accept.
I'm using django validators and python-magic to check the mime type of uploaded documents and accept only pdf, zip and rar files.
Accepted mime-types are:
'application/pdf’, 
'application/zip’, 'multipart/x-zip’, 'application/x-zip-compressed’, 'application/x-compressed',
 'application/rar’, 'application/x-rar’ 'application/x-rar-compressed’, 'compressed/rar',
The problem is that sometimes pdf files seem to have 'application/octet-stream' as mime-type.
'application/octet-stream' means generic binary file, so I can't simply add that mime type to the list of accepted files, because in that case also other files such es excel files would be accepted, and I don't want that to happen.
How can I do in this case?
Thanks in advance.