Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21400
| Date | 2012-03-08 17:11 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Finding MIME type for a data stream |
| References | <%U96r.32867$082.25394@newsfe04.iad> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.518.1331244722.3037.python-list@python.org> (permalink) |
On 03/08/2012 04:55 PM, 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. > > Also, it seems like image/png works for other types > of image data, while image/foo does not, yet I'm afraid > that not every browser will play along as nicely. > > Thanks! > > Tobiah First step, ask the authors of the database what format of data this blob is in. Failing that, write the same data locally as a binary file, and see what application can open it. Or if you're on a Linux system, run file on it. "file" can identify most data formats (not just images) just by looking at the data. That assumes, of course, that there's any consistency in the data coming out of the database. What happens if next time this blob is an Excel spreadsheet? -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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