【问题标题】:Suppose I have a StringIO file. How can I use python-magic to check its file type? [closed]假设我有一个 StringIO 文件。如何使用 python-magic 检查其文件类型? [关闭]
【发布时间】:2011-06-08 08:00:40
【问题描述】:
import StringIO
import magic

m = magic.Magic()
thefile = StringIO.StringIO(request.raw_post_data)  # I got this from Django. ajax file uploader.

现在怎么办?

【问题讨论】:

    标签: python string file mime-types stringio


    【解决方案1】:

    ...应该很简单:

     >>> m.from_buffer(thefile.read(1024))
    'PDF document, version 1.2'
    

    【讨论】:

      【解决方案2】:

      看来您需要使用 from_buffer 方法。

      m.from_buffer(theFile)
      

      【讨论】:

        猜你喜欢
        • 2011-06-08
        • 2015-03-23
        • 1970-01-01
        • 2021-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-01
        • 2015-09-02
        相关资源
        最近更新 更多