srikanth wrote:
Hi,

  I am using an external method to load an Image from the harddrive. The
external method is as follows:

from email.MIMEImage import MIMEImage
##parameters=filename
def getDocument(filename):
      fname = '/mnt/'+filename;
        input = open(fname,'r')
        content = MIMEImage( input.read( ) )
        input.close( )
        return content


When I try to display the content in the webpage what I actually got is
all raw data of the file rather the image. So how can I convert the raw data to be dispalyed as image in the
webpage. I am using ZPT to display the web page (image). If its dtml I
could have used <dtml-mime> tag is there any equivalent to that in ZPT.


Any suggestion would be a gr8 help.

It is not clear exactly how you are using the Page Template. Typically the page would have an img tag that calls a python script that calls the External Method. Remember the web browser fetches the image separately after the html has been received - so your img tag might look like this:
<img src="getImage?filename=whatever" ...> and your getImage python script would look like this:


(type, encoding) = context.getMimeType(context.REQUEST.filename)
context.REQUEST.RESPONSE.setHeader('Content-Type', type)
context.REQUEST.RESPONSE.setHeader('Content-Disposition', 'inline;
return context.getDocumentCall(context.REQUEST.filename)

where getDocumentCall is the name of your External Method that calls the getDocument External Method and getMimeType is another External Method that looks like this:

import mimetypes
def getMimeType(filename):
    return mimetypes.guess_type(filename)

and your own external method would look like this:

> ##parameters=filename
> def getDocument(filename):
>       fname = '/mnt/'+filename;
>    input = open(fname,'r')
>    content = input.read( )
>    input.close( )
>    return content

At the moment you seem to have skipped a step.

HTH

Cliff

Ta.


_______________________________________________
Zope maillist - Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________
Zope maillist - Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to