I have a piece of code that handles file uploads for me, and ideally I want to accept only text files (csv, tab delimited files, etc.) So I added this chunk of code:
mimetype = magic.from_buffer(request.FILES['docfile'].read(512), mime=True)
if form.is_valid() and mimetype == 'text/plain':
....
Just recently one of my users tried uploading a text file and the system rejected it, the mime for that file is:
file --mime-type -b input_file.txt
application/octet-stream
And of course, all of the previously uploaded files have been text/plain. What's the difference between these two? Is there a more "global" way to check if a file is a text file?