ZopeMag's mascot the ZOPE fish

# if a filename was specified; e.g. "downloads/myFile.tgz"
# 'traverse_subpath' is a list like ['BinaryDataExample', 'downloads', 'myFile.tgz'] built by
# splitting the URL 'BinaryDataExample/downloads/myFile.tgz'

if len( traverse_subpath ) == 1:

  # e.g. filename = myFile.tgz
  filename = traverse_subpath[ 0 ]
  filedata = container.sql_getDownloadData( filename = filename )[0][0]

  # browser / proxy specific declarations; 
  # see also the "index_html()" method in \lib\python\OFS\Image.py

  RESPONSE.setHeader( 'Content-Type', 'application/octet-stream' )

  # tell the browser that it will receive bytes
  RESPONSE.setHeader( 'Accept-Ranges', 'bytes' )

  # the next 2 lines are required: so downloading files will also work in older Netscape browsers
  RESPONSE.setHeader( 'Last-Modified', container.ZopeTime().rfc822() )
  RESPONSE.setHeader( 'ETag', 'ts%s' % str( container.ZopeTime().timeTime() )[ 2: ] )  

  return filedata

# incorrect call
else:

  RESPONSE.redirect( 'index.html' )



Home   Subscribe   FAQ   Contact   Write for us   Privacy Policy   Weekly News   PyZine   opensourcexperts.com  

Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag Zope/Plone hosting by Nidelven IT