Content-type for a method or script
I need to render an image with some logic from a request in an external (non-zope page) example request from html: <img src="http://zope/images/header.gif?UID=sdflkj"> DTML_Method "header.gif" <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var mytestgif> my ID=<dtml-var UID> mytestgif is an 'Image' in zope. It renders fine when I test the URL http://zope/images/header.gif?UID=sdflkj But, the Method does not render when called from within <img src> in another page!!! I got the same result with a script. Please point me in the right direction... Thanks Trevor
Trevor Toenjes wrote:
I need to render an image with some logic from a request in an external (non-zope page)
example request from html: <img src="http://zope/images/header.gif?UID=sdflkj">
DTML_Method "header.gif" <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var mytestgif> my ID=<dtml-var UID>
mytestgif is an 'Image' in zope. It renders fine when I test the URL http://zope/images/header.gif?UID=sdflkj
Yeah, but did you look at the file you _really_ got? It was an html-file with an image tag in it, I bet - bad food for another image tag. <dtml-var image> will not return the image-data, but the above mentioned image tag. Try <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var "mytestgif.data"> And beware, it will also work on internet explorer if you don't set the right header, but that's plain wrong. What do you want to achieve with that my ID=<dtml-var UID> stuff? cheers, oliver
Try <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var "mytestgif.data"> Thanks. Yes, that works alone to serve the image. But when I include something like this below, it doesnt work. I dont know why...
<dtml-if expr="UID == 'myid'> <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var expr="mytestgif.data"> <dtml-else> <img src="http://anotherdomain/bar.jpg"> </dtml-if> Thank you for follow-up help. Trevor
Trevor Toenjes wrote:
I need to render an image with some logic from a request in an external (non-zope page)
example request from html: <img src="http://zope/images/header.gif?UID=sdflkj">
DTML_Method "header.gif" <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var mytestgif> my ID=<dtml-var UID>
mytestgif is an 'Image' in zope. It renders fine when I test the URL http://zope/images/header.gif?UID=sdflkj
Yeah, but did you look at the file you _really_ got? It was an html-file with an image tag in it, I bet - bad food for another image tag. <dtml-var image> will not return the image-data, but the above mentioned image tag.
Try <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var "mytestgif.data">
And beware, it will also work on internet explorer if you don't set the right header, but that's plain wrong. What do you want to achieve with that my ID=<dtml-var UID> stuff?
cheers, oliver
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Trevor Toenjes wrote:
Try <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var "mytestgif.data">
Thanks. Yes, that works alone to serve the image. But when I include something like this below, it doesnt work. I dont know why...
<dtml-if expr="UID == 'myid'> <dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')"> <dtml-var expr="mytestgif.data"> <dtml-else> <img src="http://anotherdomain/bar.jpg"> </dtml-if>
Because you now serve several whitespaces (i.e. spaces, newline, carriage-returns whatever) together with the imagedata. To illustrate <dtml-if expr="UID == 'myid'>\n ____<dtml-call "RESPONSE.setHeader('Content-Type', 'image/gif')">\n ____<dtml-var expr="mytestgif.data">\n <dtml-else>\n ____<img src="http://anotherdomain/bar.jpg">\n </dtml-if>\n I have replaced spaces with _ and newline with \n. So if UID == 'myid' the browser gets: \n ____Content-Type: image/gif\n ____<dataofthepicture>\n \n \n \n You see, that is wrong, it should get: Content-Type: image/gif\n <dataofthepicture> This is ugly to get right in a dtml-method, you have to put it all in one line, without _any_ whitespace. Can't you just do (or similar, this is untested) the follwing? <dtml-if expr="UID == 'myid'> <dtml-return "RESPONSE.redirect('http://hostname/mytestgif')"> <dtml-else> <dtml-return "RESPONSE.redirect('http://anotherdomain/bar.jpg')"> </dtml-if> cheers, oliver
participants (2)
-
Oliver Bleutgen -
Trevor Toenjes