[Zope] Set MIME type using ZPT

Cliff Ford Cliff.Ford at ed.ac.uk
Wed Apr 6 03:56:43 EDT 2005


srikanth wrote:
> Hi,
> 
>    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
> src="loadImage?filename=imagename"></span>

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.

Cliff

> Because I am getting the filename from the resultset.
> Once again thanks for all your time and patience.
> Any help would be gr8.
> 
> Ta.
> Srikanth.
> 
> -----Original Message-----
> From: zope-bounces at zope.org [mailto:zope-bounces at zope.org] On Behalf Of
> Cliff Ford
> Sent: Monday, April 04, 2005 11:15 PM
> Cc: zope at zope.org
> Subject: Re: [Zope] Set MIME type using ZPT
> 
> 
> 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 at 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 at 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 )
> 
> 


More information about the Zope mailing list