srikanth wrote:

I tried this one. But the html page takes the parameter as a string
but doenst Execute the pyhton function. I got all the functions (External methods)
all set.

The img tag I used is:
<span tal:define="imagename result/filename"><Img

Have a look at the generated html source. You have not said wither the probem is a mal-formed image tag, or the image tag failing to fetch the image.

Also, pay attention to Tino's comments on seurity. I only ever use a Serial Number, not Filename - that comes from a database.

Don't forget that image tags should have width, height and alt attributes.


Because I am getting the filename from the resultset.
Once again thanks for all your time and patience.
Any help would be gr8.


-----Original Message-----
Cliff Ford
Sent: Monday, April 04, 2005 11:15 PM
Subject: Re: [Zope] Set MIME type using ZPT

srikanth wrote:


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

from email.MIMEImage import MIMEImage
def getDocument(filename):
     fname = '/mnt/'+filename;
        input = open(fname,'r')
        content = MIMEImage( ) )
        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.close( )
 >   return content

At the moment you seem to have skipped a step.




Zope maillist -
** No cross posts or HTML encoding! **
(Related lists - )

Zope maillist -
** No cross posts or HTML encoding! **
(Related lists - )

Zope maillist -
** No cross posts or HTML encoding! **
(Related lists - )

Reply via email to