[Zope] Method to download a file

Francois-Regis CHALAOUX Francois-Regis.CHALAOUX@sanofi-synthelabo.com
Wed, 5 Apr 2000 16:28:00 +0200


Hi All,

My problem is to download a file from a FORM. When I click on Submit button I
would like download a file via a dialog "save as". As my following code shows
you, ids input is not used for the moment, later I will construct the filename
to download with this ids. But for the moment I got an error :(.
Is it the right way to do it, what is my error, etc .. I suspect something
with RESPONSE but I can't find something in mailing-list or doc on that stuff.

Help appreciated.

FR.


DownloalForm
============
<FORM ACTION=getPDB METHOD=POST>
<INPUT TYPE=TEXT Name=ids>
<INPUT TYPE=SUMBIT NAME=Submit>

getPDB method
=============
<dtml-var "getfiles(REQUEST['ids'])">

getfiles.py Extension file
===========================
def getfiles(ids):
  PickleJar = Trinket('/me/foo-ids.gz','x/gzip')  
  PickleJar.download(RESPONSE)
 
class Trinket:
  def __init__(self,path,type):
    self.path,self.type = path, type
    
  def download(self, RESPONSE):
    RESPONSE['Content-type']=self.type
    return open(self.path).read()

Errors
=====
<!--
 Error type:  NameError
 Error value: RESPONSE
 -->
</BODY></HTML>
<PRE>
Traceback (innermost last):
  File /usr/local/Zope-2/lib/python/ZPublisher/Publish.py, line 214, in
publish_module
  File /usr/local/Zope-2/lib/python/ZPublisher/Publish.py, line 179, in
publish
  File /usr/local/Zope-2/lib/python/Zope/__init__.py, line 201, in
zpublisher_exception_hook
    (Object: ElementWithAttributes)
  File /usr/local/Zope-2/lib/python/ZPublisher/Publish.py, line 165, in
publish
  File /usr/local/Zope-2/lib/python/ZPublisher/mapply.py, line 160, in mapply
    (Object: getPDB)
  File /usr/local/Zope-2/lib/python/ZPublisher/Publish.py, line 102, in
call_object
    (Object: getPDB)
  File /usr/local/Zope-2/lib/python/OFS/DTMLMethod.py, line 145, in __call__
    (Object: getPDB)
  File /usr/local/Zope-2/lib/python/DocumentTemplate/DT_String.py, line 502,
in __call__
    (Object: getPDB)
  File /usr/local/Zope-2/lib/python/DocumentTemplate/DT_Util.py, line 321, in
eval
    (Object: getfiles(REQUEST['ids']))
  File &lt;string&gt;, line 0, in ?
  File /usr/local/Zope-2/lib/python/Products/ExternalMethod/ExternalMethod.py,
line 246, in __call__
    (Object: getfiles)
    (Info: (('eeee',), {}, None))
  File /usr/local/Zope-2/Extensions/getfiles.py, line 3, in getfiles
NameError: (see above)