Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21422
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Finding MIME type for a data stream |
| Date | 2012-03-09 11:50 +0100 |
| Organization | None |
| References | <%U96r.32867$082.25394@newsfe04.iad> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.531.1331290226.3037.python-list@python.org> (permalink) |
Tobiah wrote:
> I'm pulling image data from a database blob, and serving
> it from a web2py app. I have to send the correct
> Content-Type header, so I need to detect the image type.
>
> Everything that I've found on the web so far, needs a file
> name on the disk, but I only have the data.
>
> It looks like the 'magic' package might be of use, but
> I can't find any documentation for it.
After some try-and-error and a look into example.py:
>>> m = magic.open(magic.MAGIC_MIME_TYPE)
>>> m.load()
0
>>> sample = open("tmp.png").read()
>>> m.buffer(sample)
'image/png'
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 13:55 -0800
Re: Finding MIME type for a data stream Dave Angel <d@davea.name> - 2012-03-08 17:11 -0500
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 14:28 -0800
Re: Finding MIME type for a data stream Dave Angel <d@davea.name> - 2012-03-08 17:56 -0500
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 15:40 -0800
Re: Finding MIME type for a data stream Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-03-08 21:04 -0500
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-09 08:40 -0800
Re: Finding MIME type for a data stream Jon Clements <joncle@googlemail.com> - 2012-03-08 18:31 -0800
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-09 09:53 -0800
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 14:34 -0800
Re: Finding MIME type for a data stream Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2012-03-09 03:12 +0100
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-09 08:35 -0800
Re: Finding MIME type for a data stream Peter Otten <__peter__@web.de> - 2012-03-09 11:50 +0100
csiph-web