ZPublisher: How to set the mime header?
Hi! I'm not using zope, but I'm using ZPublisher and ZServer. I'm coding a very simple counter module (with PIL). How could I set the mime header to image/gif and return an image?
Oliver Thuns wrote:
Hi!
I'm not using zope, but I'm using ZPublisher and ZServer. I'm coding a very simple counter module (with PIL). How could I set the mime header to image/gif and return an image?
This is in the Zope FAQ, actually, at http://zdp.zope.org/FAQ/external. At least I think I'd apply to ZPublisher as well? How do I return an image from an External Method? Example (for a png image): def foo(self, RESPONSE): # set the header RESPONSE['content-type'] = 'image/png' # return the actual image data return mkimage() Another way to set the header information is: RESPONSE.setHeader('content-type','image/png') Regards, Martijn
I've been using this.... (Zope example but should work with ZServer) It was fully expecting to have to mess about with headers to get browsers to recognise the gif, but broswers seem to know a gif when they get one! This example returns gifs in a browser when you do .... http://mysite/renderGif or even <IMG src="renderGif"> (I'm fully prepared to admit there may be better ways of doing it) ;)_ Cheers, Andy. def renderGif(self, size=500, counter=1): """Draw a pie chart""" im = PIL.Image.new('RGB', (size,size)) # Do GIF manipulation stuff here! outFile = cStringIO.StringIO() im.save(outFile, 'GIF') outFile.seek(0) outString = outFile.read() return outString
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Oliver Thuns Sent: Tuesday, March 16, 1999 1:44 PM To: zope@zope.org Subject: [Zope] ZPublisher: How to set the mime header?
Hi!
I'm not using zope, but I'm using ZPublisher and ZServer. I'm coding a very simple counter module (with PIL). How could I set the mime header to image/gif and return an image?
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(For developer-specific issues, use the companion list, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
On Tue, Mar 16, 1999 at 07:44:18PM +0100, Oliver Thuns wrote:
Hi!
I'm not using zope, but I'm using ZPublisher and ZServer. I'm coding a very simple counter module (with PIL). How could I set the mime header to image/gif and return an image?
When using Zope to publish XML documents (using DTML Document objects) I often write: <!--#call expr="REQUEST.setHeader('Content-Type', 'text/xml')--> Some part of Zope tries to guess the Content-Type otherwise. A lot of this code is directly shared between Zope and Z Publisher, so you might see similar behavior. Cheers, Eric
participants (4)
-
Andy Smith -
Eric Kidd -
Martijn Faassen -
Oliver Thuns