【发布时间】:2010-11-13 02:32:03
【问题描述】:
这只是一个用户上传文件。
【问题讨论】:
标签: python django linux file unix
这只是一个用户上传文件。
【问题讨论】:
标签: python django linux file unix
UploadedFile.content_type 将返回在上传时与文件一起发送的内容类型标头。
如果您还需要在保存文件后检查文件,您可以使用 python 中的 mimetypes 模块。但它似乎只根据文件扩展名进行检查。
import mimetypes
file_type, file_encoding = mimetypes.guess_type('/path/to/file')
print 'File-type: %s\nFile-encoding: %s' % (file_type, file_encoding)
如果您有默认未检测到的文件类型要求,您也可以在使用 guess_type 之前将类型添加到 mimetypes:
mimetypes.add_type('font/ttf', '.ttf')
【讨论】:
UploadedFile.content_type
查看http://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs了解更多信息
【讨论】: