[Zope] Stuffing file objects into my objects

Damon Eckhoff eckhoffd@missouri.edu
Thu, 13 Jun 2002 10:32:44 -0500


I have no concrete idea of what I'm doing, but I've managed to get pretty
far...

I have a product class that has an attribute that is an OFS.Image.File
object.  I have setter and getter methods called setFile() and getFile(),
respectively.

So far I can upload files and they get stored into my product, and I can
even get the File objects out (via scripting).  But what I'm not sure how to
do is to access the file objects via a web path.  Something to the effect of
/stuff/product_instance/getFile.

At this point /stuff/product_instance/getFile almost works.  It works fine
with images, text files, pdf on the Mac... But word documents don't seem to
work, as if the content-type isn't being recognized by the browser on the
download, i.e. Word docs are rendered as text files in the browser window.
I have had this problem before, but my solution was to attach a file
precondition that set some response headers:

hdr_name = "content-disposition"
hdr_value = 'attachment; filename="%s"' % filename
context.REQUEST.RESPONSE.setHeader( hdr_name, hdr_value )

But now I have the File object embedded inside another object.  How could I
attach a precondition that would get called if the file is accessed via
/stuff/product_instance/getFile?  When I tried passing the name of an
external script to the File constructor, but that doesn't seem to get
called.

Any ideas or help?

Damon.