Am Dienstag, den 05.04.2005, 13:11 -0700 schrieb srikanth:
> 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.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.

This is not a domain for templating languages like DTML or ZPT.
Images are read seperately by the client (get a sniffer like
shanes tcpwatch or tcpflow and see whats going on there)
So your external method has to set the headers.
Unfortunalely you open a huge security hole with your solution
and by not reading the python documentation carefully ;)
fname = '/mnt/'+filename; <---
if I put a filename like "../etc/passwd" I start to have fun.

Ah, and image data for web pages are raw. So you dont need
mimeimage alltogether. Just open().read() 
Again, if you want performance, you should use:

from ZPublisher.Iterators import filestream_iterator

return filestream_iterator(filenameondisk,'rb')


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

Reply via email to