Reputation: 319
I have tried:
self.data['uploaded_file'].content_type
However, this gives an error that says the object lacks a content_type attribute.
Any ideas as to why? Thank you.
What is the best way to verify file type in Django forms?
Upvotes: 0
Views: 216
Reputation: 876
How could you tell a file is binary file or text or some other stuff? Perhaps using the file extension is a way, but not always makes sense.
Upvotes: 0
Reputation: 798526
The content_type
attribute is only present on the UploadedFile
instances contained in request.FILES
; you will need to get the content type from that, or use magic
to get it from the raw file data.
Upvotes: 1