Reputation: 271614
it's just a user upload a file.
Upvotes: 0
Views: 1737
Reputation: 685
UploadedFile.content_type will return the content-type header that was sent with the file when uploaded at the time of upload.
If you also need to check files after they are saved you can use the mimetypes module in python. But it appears to only check based on the file extension.
import mimetypes
file_type, file_encoding = mimetypes.guess_type('/path/to/file')
print 'File-type: %s\nFile-encoding: %s' % (file_type, file_encoding)
And if you have file-type requirements that are not detected by default you can add the types to mimetypes simply too before using guess_type:
mimetypes.add_type('font/ttf', '.ttf')
Upvotes: 3
Reputation: 12423
UploadedFile.content_type
Check http://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs for more info
Upvotes: 2