[Zope] ZPublisher: How to set the mime header?

Martijn Faassen M.Faassen@vet.uu.nl
Tue, 16 Mar 1999 20:01:14 +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?

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