[Zope] Returning Image Data from a Product

Max M maxm@mxm.dk
Tue, 26 Feb 2002 22:00:47 +0000


Terry Hancock wrote:

>I've tried:
>
>   return self.result_image
>
>which returns a serialized image tag (i.e. just like
>
>   return self.result_image.tag()
>
>which I've also tried).
>
>   return self.result_image.data
>
>returns the PNG image alright, but the mime type is
>set to 'text/plain'!
>
>The kicker is, I have a related module which does do
>this successfully, by simply using:
> 
>   return self.result_image
>
I have had a similar problem once.

The problem is probably that the id of your imagefile and the attribute 
name should be the same.

Something like this in your product:

from OFS import Image
self.

result_image = Image.Image('result_image', imageTitle, file, content_type, precondition)


instead of:
from OFS import Image
self.image = Image.Image('result_image', imageTitle, file, content_type, 
precondition)

Or else you are confusing matters. The tag will be made like:

<img src="result_image">

but you image will actually have the url <img src="image">

I remember submitting a one line patch but never got an answer and can 
no longer remember what it was. But it was something about setting the 
id of the image afterwards. You could probably browse the source for 
"tag()" method in the image Module and then set it something like; 
self.image._id = 'image' if that is a good solution for you.

regards Max M