RESPONSE.setHeader
Hi, Does anyone know how to setHeader of the RESPONSE to a document in Zope which would ordinarily be read as an html file will now be downloaded? I list some files in a page and then I want to be able to download these documents, but of course the browser will load and render them. I have tried: <dtml-call "RESPONSE.setHeader('Content-Disposition','Attachment; Filename=' + document)"> where document is the &dtml-absolute_url; of the object I want. But it will give me a popup window to save the HTML file of the page that lists the files I want available for download. <dtml-call "RESPONSE.setHeader('refresh', '4;URL=' + document)"> Will of course get me the correct page as well, but again, the browser will render it since it is in fact of DTML Document type... But how do you force a download? Thanks again, Paz
Hi Paul, you have to set the header on the resource you want to download, not on the page containing the links. You can make a simple download method like this: <dtml-call "RESPONSE.setHeader('content-type','application/octet-stream')> <dtml-call "RESPONSE.setHeader('Content-Disposition','Attachment; Filename=' + id() +'.txt')"> <dtml-return "_[id()]"> as a method "download", so you can use yourdocument/download do download yourdocument.txt HTH. Tino Wildenhain PS: note: untested. May be you have to vary some things in the source, (like id() ) but it schould be good for a starting point. --On Dienstag, 29. Mai 2001 13:17 +0200 Paul Zwarts <paz@oratrix.com> wrote:
Hi,
Does anyone know how to setHeader of the RESPONSE to a document in Zope which would ordinarily be read as an html file will now be downloaded?
I list some files in a page and then I want to be able to download these documents, but of course the browser will load and render them.
I have tried: <dtml-call "RESPONSE.setHeader('Content-Disposition','Attachment; Filename=' + document)">
where document is the &dtml-absolute_url; of the object I want. But it will give me a popup window to save the HTML file of the page that lists the files I want available for download.
<dtml-call "RESPONSE.setHeader('refresh', '4;URL=' + document)">
Will of course get me the correct page as well, but again, the browser will render it since it is in fact of DTML Document type... But how do you force a download?
Thanks again, Paz
_______________________________________________ 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 )
Hi Tino, Thanks for the response. I *think* I understand what you mean. Here is the layout SMILTests <- the viewing document that scans the following folders for documents and then lays them out as various types and recognizes the differences by their extension SMILTests - viewing file getDoc - your suggested method Interop (folder) Animation (folder something.smil - a .smil file to be downloaded something.smil.html - the corresponding source file to read Media (more folders) ... ... The SMILTests document will compile a list per folder. From this same document, I want to cause the download of the requested file, which btw, are ALL DTML Documents. <a href="getDoc?document=something.smil&area=Animation">this file</a> So it goes to getDoc which has: <dtml-with Interop> <dtml-with "_.getitem('area')"> <dtml-call "RESPONSE.setHeader('content-type','application/octet-stream')"> <dtml-call "RESPONSE.setHeader('Content-Disposition','Attachment; Filename=' + document)"> <dtml-return "_[document]"> </dtml-with> </dtml-with> Which gets itself to the correct folder in a folder, and the file... And the <dtml-return> should var the ultimate destination into the current method, or......? Thanks, Paz So what you are saying is in the SMILTests document, the a href should look like -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Tino Wildenhain Sent: 29 May 2001 13:59 To: Paul Zwarts; Zope Subject: Re: [Zope] RESPONSE.setHeader Hi Paul, you have to set the header on the resource you want to download, not on the page containing the links. You can make a simple download method like this: <dtml-call "RESPONSE.setHeader('content-type','application/octet-stream')> <dtml-call "RESPONSE.setHeader('Content-Disposition','Attachment; Filename=' + id() +'.txt')"> <dtml-return "_[id()]"> as a method "download", so you can use yourdocument/download do download yourdocument.txt HTH. Tino Wildenhain PS: note: untested. May be you have to vary some things in the source, (like id() ) but it schould be good for a starting point.
participants (2)
-
Paul Zwarts -
Tino Wildenhain