[Zope] returning a dynamically created zip file

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Jun 29 15:14:21 EDT 2004


I have a class in a zope file that returns a zip file.  The zip file
is created dynamically.  Currently, I save this zip file to a zope
folder and return it's URL.  I was wondering if there was a way to
avoid saving it to the zope file system.

Here is what I have

    def all_zipped(self, REQUEST=None, *args, **kwargs):
        """
        Get all the documents from the doc template folder as a zip
        """
        docFolder = self.get_docfolder()

        tmpfile = TemporaryFile() # stringio bombed
        zip = zipfile.ZipFile(tmpfile, 'w')
        #snip write the zip file
        zip.close()

        id = 'docs.zip'
        if id in docFolder.objectIds():
            docFolder._delObject(id)

        tmpfile.seek(0)
        docFolder._setObject(id, File(id, id, tmpfile.read(), 'application/zip', precondition=''))        
        fileo = docFolder._getOb(id)

        REQUEST.RESPONSE.redirect(fileo.absolute_url())


I tried

        tmpfile.seek(0)
        return File(id, id, tmpfile.read(), 'application/zip', precondition='')

and this did launch the file save dialog in my browser, but the
content type wasn't set correctly.  What is the best way to do this?

Also, I feel like I must be doing something wrong calling all these
leading underscore methods of my folders (_delObject, _setObect,
_getObject).  What is the preferred way to make these calls?

Thanks,
John Hunter


More information about the Zope mailing list