[Zope] Serving external files

Allen Wallis allen@rrsg.ee.uct.ac.za
Tue, 28 Mar 2000 10:09:10 +0200


Hi,
I have some questions about serving external files:

I want to be able to serve a file that is external to Zope's Object
database. This file would probably be a binary file. So far, I have an
external method that reads the data from the file, and sets the header
of the RESPONSE object passed to it. The external method looks something
like:
    def readFile(self, REQUEST, RESPONSE):
        ...
        data = f.read()   # where f is the binary file, and has been
opened
       RESPONSE.setHeader("Content-Type", "application/data")
        return data

The zope id of the external method is "getFile".

I have a dtml method that calls this external method, using
<dtml-var "getFile(REQUEST, RESPONSE)">
The id of this dtml method is "download".
Say I have a dtm document with something like
<a href="download">SomeFile.dat</a>

This works, and the file is downloaded correctly. I want to know firstly
whether there is a better way of achieving this.
Secondly, when the user clicks on the SomeFile.dat hyperlink, and the
browser's "save as" dialog pops up, the browser uses the id of the dtml
method "download" as the filename in the dialog. Obviously I would
rather this dialog shows the name of the file that will be downloaded.
How can I change this? I can't rename the dtml method suitable for each
different filname that might be downloaded, so where else can I alter
this behaviour?

Thanks
Allen