Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.105 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'failing': 0.09; 'binary': 0.13; 'thanks!': 0.14; '"file"': 0.16; 'received:192.168.1.104': 0.16; 'cc:addr:python-list': 0.16; 'linux': 0.17; 'wrote:': 0.18; 'seems': 0.20; 'cc:no real name:2**0': 0.21; 'detect': 0.21; 'file,': 0.21; 'header:In-Reply-To:1': 0.22; 'sfxlen:0': 0.23; 'subject:data': 0.25; 'cc:2**0': 0.26; 'looks': 0.27; "i'm": 0.28; 'cc:addr:python.org': 0.29; 'correct': 0.29; 'pm,': 0.29; 'far,': 0.30; 'header,': 0.30; "i've": 0.32; 'does': 0.32; 'that,': 0.32; 'yet': 0.32; "can't": 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'file': 0.34; '(not': 0.35; 'data.': 0.36; 'run': 0.37; 'but': 0.37; 'happens': 0.38; 'not,': 0.38; 'received:192': 0.38; 'authors': 0.38; 'format': 0.38; 'data': 0.38; 'open': 0.38; 'received:192.168.1': 0.39; 'data,': 0.39; 'application': 0.40; 'might': 0.40; 'course,': 0.62; 'browser': 0.62; 'afraid': 0.63; 'serving': 0.68; 'header:Reply-To:1': 0.70; 'reply-to:no real name:2**0': 0.72; 'database.': 0.74; 'blob': 0.84; 'subject:stream': 0.84; 'locally': 0.91; 'step,': 0.93 Date: Thu, 08 Mar 2012 17:11:26 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Thunderbird/3.1.19 MIME-Version: 1.0 To: Tobiah Subject: Re: Finding MIME type for a data stream References: <%U96r.32867$082.25394@newsfe04.iad> In-Reply-To: <%U96r.32867$082.25394@newsfe04.iad> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:3RVtOOOTs2ktpgFf3ySq6xls0SUM+kUv/fYiK+14soW 3QPNNINJ2LVEQhCaZLS9/gihApgRo9ucQ21hC6EMmxW/YtmBsM 1EX15CxGmxXEUudg/CU8ogY5aJMylfRF4OFBd6imiGQavYXHzA pagHWYb23gjnlS0IMPyJ9EPSLq9czV3w3F+/foAGTEbVE/cqEF jNXWvFKWiG6bw0EjJUGnOPkKimgIxcGscXURvOyiaOy5+FYPT6 h0Jxb8P8G2MnJOwpwswkJWj4HCXoD/EuMFnFLIkRzp0hfGbzAj Qc+KHr8WtOiACsLsT56cTInWYOucrUq6xFcFrqFD4MCLVnQGw= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331244722 news.xs4all.nl 6975 [2001:888:2000:d::a6]:43619 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21400 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