[Zope] Serving Files from Filesystem

Thomas Guettler zopestoller@thomas-guettler.de
Wed, 24 Jul 2002 17:13:57 +0200


Reinoud van Leeuwen wrote:

> On Wed, Jul 24, 2002 at 02:53:46PM +0200, Thomas Guettler wrote:
> 
>>Hi!
>>
>>I want to make files from the filesystem down- and uploadable
>>via browser.
>>
>>It is needed for a python product. No TTH editing, dtml or zpt.
>>
>>Which products are available?
>>
> 
> WebDav? (in Internet Explorer: File -> open -> (enter URL and select 'Open 
> as WebFolder').
> Now you have a explorer window open on your zope folder where you can drag 
> and drop files


I tried WebDAV three month ago. It was not stable. The files got
read only after the first access. I think it is a bug in MS-Office.

But I just want to server a simple file. I wrote it myself, quite easy

If someone is interested:

     def downloadAttachment(self, file=None, REQUEST=None):
         "Download attachment 'file' to browser"
         if file==None:
             raise 'You must specify a file to download'
         abs_filename=os.path.join(self.external_documents_home,
                                   self.id,
                                   file)
         fd=open(abs_filename, "rb")
         file_content=fd.read()
         print "file_content: %s" % file_content[:20]
         fd.close()
         if REQUEST:
             content_type, content_encoding = mimetypes.guess_type(abs_filename)
             print "ct ce:", content_type, content_encoding
             if content_type:
                 REQUEST.RESPONSE.setHeader('Content-Type',
                                            content_type)
             if content_encoding:
                 REQUEST.RESPONSE.setHeader('Content-Encoding',
                                            content_encoding)
         return file_content

thomas