how to python mimetypes.guess_type from a file-like object

后端 未结 3 1156
渐次进展
渐次进展 2021-01-18 12:28
>>> mimetypes.guess_type(\'picture.jpg\')
(\'image/jpeg\', None)

Now I have a file-like object, (eg. stingIO), which content is image\'s d

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-18 12:42

    >>> import mimetypes
    >>> print(mimetypes.MimeTypes().guess_type('my_file.txt')[0])
    text/plain
    

    Reference : https://www.tutorialspoint.com/How-to-find-the-mime-type-of-a-file-in-Python

提交回复
热议问题