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
--On Dienstag, 29. Juni 2004 14:14 Uhr -0500 John Hunter <jdhunter@ace.bsd.uchicago.edu> wrote:
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.
Zope has no file system, Zope has an object oriented database. You can spit out the file direct from the temporary file. there is some code in PloneCollectorNG that does the same with PDF files (grep for asPDF()). -aj
Hi, I've a big problem with html2pdf. I've a zpt with an image "myimage.jpg". The content of "myimage.jpg" changes every time. When i call the script html2pdf on the page the pdf is generated correctly but....if i recall subsequently the page I have always the first "myimage.jpg". It seems the image "myimage.jpg" is cached (i don't know where! I haven't set anything about cache). how can I resolve this problem? Thanks a lot!! Massimiliano
On Wed, Jun 30, 2004 at 09:44:15AM +0200, trashMan wrote:
I've a zpt with an image "myimage.jpg". The content of "myimage.jpg" changes every time.
Cache. The very first idea (to think less) it could be generate random image name (title?), if it changes so often sequentially. Second, be sure you turn off browser cache by HTTP directives. -- 暮 2B OR NOT 2B == FF
I don't use cache on my browser and ...the script works on the server!! Massi -----Messaggio originale----- Da: zope-bounces+trashman=httconsulting.com@zope.org [mailto:zope-bounces+trashman=httconsulting.com@zope.org] Per conto di trashMan Inviato: mercoledì 30 giugno 2004 9.44 A: zope@zope.org Oggetto: [Zope] html2pdf Hi, I've a big problem with html2pdf. I've a zpt with an image "myimage.jpg". The content of "myimage.jpg" changes every time. When i call the script html2pdf on the page the pdf is generated correctly but....if i recall subsequently the page I have always the first "myimage.jpg". It seems the image "myimage.jpg" is cached (i don't know where! I haven't set anything about cache). how can I resolve this problem? Thanks a lot!! Massimiliano _______________________________________________ Zope maillist - Zope@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 )
From: "trashMan" <trashman@httconsulting.com>
I've a big problem with html2pdf. I've a zpt with an image "myimage.jpg". The content of "myimage.jpg" changes every time. When i call the script html2pdf on the page the pdf is generated correctly but....if i recall subsequently the page I have always the first "myimage.jpg". It seems the image "myimage.jpg" is cached (i don't know where! I haven't set anything about cache). how can I resolve this problem?
To make sure you are not storing a version in the browser cache use the ctrl + F5 (IE, I don't know what the NN equivalent is) to reload the page. ctrl + F5 will cause the browser to request a version of the page from the server (not serve up the page from the browser cache - which is done if the timing/caching paramaters in the page header indicate that the page has not expired). You can also try embedding timing/caching parameters in the page header: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta http-equiv="Content-Language" content="en-ca"> <meta http-equiv="expires" content="Sat, 01 Jan 2001 00:00:00 GMT"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="pragma" content="no-cache"> </head> HTH Jonathan
trashMan wrote:
I've a big problem with html2pdf. I've a zpt with an image "myimage.jpg". The content of "myimage.jpg" changes every time. When i call the script html2pdf on the page the pdf is generated correctly but....if i recall subsequently the page I have always the first "myimage.jpg". It seems the image "myimage.jpg" is cached (i don't know where! I haven't set anything about cache). how can I resolve this problem?
I think this is nothing which is related to the html2pdf-script as it is. Maybe this is a problem of HTMLDoc. Try to call it from command-line to test if it works properly. If not, ask the HTMLDoc-Developers how to make it work... An idea: Maybe HTMLDoc creates tmp-files somewhere on the system and doesn't reload images (=> create new new-files) for already fetched images. -mj
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@ace.bsd.uchicago.edu> To: "Zope Users" <zope@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@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 )
participants (7)
-
Andreas Jung -
bo@bitute.b4net.lt -
David Hassalevris -
John Hunter -
Jonathan Hobbs -
Maik Jablonski -
trashMan