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
Allen, Try looking at the LocalFS product available on the Zope.org site. It makes folders on the physical drive look like part of the ZODB. HTH Phil phil.harris@zope.co.uk ----- Original Message ----- From: "Allen Wallis" <allen@rrsg.ee.uct.ac.za> To: <zope@zope.org> Sent: Tuesday, March 28, 2000 9:09 AM Subject: [Zope] Serving external files
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
_______________________________________________ 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 )
At 10:09 am +0200 28/3/00, Allen Wallis wrote:
Hi, I have some questions about serving external files: 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.
Yes. Use the LocalFS product, it's taken care of a lot of the things that you're battling with (I've done the same thing and am in the process of moving to LocalFS).
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?
Again, LocalFS will do this for you (my main reason for switching!). hth tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
Tony McDonald wrote:
At 10:09 am +0200 28/3/00, Allen Wallis wrote:
Hi, I have some questions about serving external files: 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.
Yes. Use the LocalFS product, it's taken care of a lot of the things that you're battling with (I've done the same thing and am in the process of moving to LocalFS).
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?
Again, LocalFS will do this for you (my main reason for switching!).
hth tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
_______________________________________________ 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 )
Thanks - I have downloaded LocalFS, but haven't tried anything substantial with it, my reason being that I needed to upload these external files as well. A user must be able to upload a file, which will be saved to the local file system, and made available for download from the local file system. The actual path to the file will be stored in a relational database (along with a whole lot of other info). If I were to use the LocalFS product for this, is it possible to add a LocalFS object dynamically (through some dtml method that gets called when a user uploads a file)? Or (better?), is it possible to set up a LocalFS object dynamically only when a user wants to download a particular file (once finished the LocalFS object is deleted). I ask since, in my case there might be many files that are uploaded, and I'm not sure what limits there are on the number of LocalFS objects that can be maintained. Any comments appreciated! thanks Allen
At 12:45 pm +0200 28/3/00, Allen Wallis wrote:
Thanks - I have downloaded LocalFS, but haven't tried anything substantial with it, my reason being that I needed to upload these external files as well. A user must be able to upload a file, which will be saved to the local file system, and made available for download from the local file system. The actual path to the file will be stored in a relational database (along with a whole lot of other info). If I were to use the LocalFS product for this, is it possible to add a LocalFS object dynamically (through some dtml method that gets called when a user uploads a file)?
Yes, but just set up a LocalFS object from the management interface and don't worry about it. If you're worried about files cluttering up the filestore, use a cron job to wipe them out. Or (better?), is it possible to set up a LocalFS object dynamically only when a user wants to download a particular file (once finished the LocalFS object is deleted). I ask since, in my case there might be many files that are uploaded, and I'm not sure what limits there are on the number of LocalFS objects that can be maintained. It uses python filesystem methods, so I reckon the number of files in a LocalFS object (ie the directory) is os limited. I sent an email to the list on the 21st March where I had some (rudimentary) dtml and python code that uploads to a LocalFS object (ie the directory that the LocalFS object is pointing to). Check it out, the subject line is [Zope] Re: [Zope-dev] RE: ZDiscussions hth tone. ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
I have downloaded LocalFS, but haven't tried anything substantial with it, my reason being that I needed to upload these external files as well.
Expect file uploading in the next version of LocalFS, which should be released in the next 2-3 weeks. -jfarr
participants (4)
-
Allen Wallis -
Jonothan Farr -
Phil Harris -
Tony McDonald