[Zope] returning a dynamically created zip file

David Hassalevris bluepaul at earthlink.net
Tue Jun 29 17:26:52 EDT 2004


John,
I have used something like this the snippet below to send pdfs (using
ReportLab) to the browser and it recognizes the content-type.

     RESPONSE.setHeader('Content-Type','application/pdf')
     RESPONSE.addHeader("Content-Disposition","filename=report.pdf")
     RESPONSE.setHeader('Content-Length',len(result))

     RESPONSE.write(result)

David

----- Original Message ----- 
From: "John Hunter" <jdhunter at ace.bsd.uchicago.edu>
To: "Zope Users" <zope at zope.org>
Sent: Tuesday, June 29, 2004 12:14 PM
Subject: [Zope] returning a dynamically created zip file


>
> 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
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )



More information about the Zope mailing list