[Zope3-Users] dynamic file creation

Michal Nowikowski godfryd at gmail.com
Fri Apr 14 13:27:35 EDT 2006


> Hi,
> On Fri, Apr 14, 2006 at 02:56:55PM +0200, Michal Nowikowski wrote:
> > Hello,
> > I'm a Zope3 newbie. I want to send to user a file while he clicks on a link.
> You won't need the IFile interface - just a simple view that sets some special
> HTTP-headers. Example:
>
> class DownloadView(BrowserView):
>         def __call__(self):
>                 rsp=self.request.response
>                 rsp.setHeader('Content-disposition','attachment; filename=download.txt')
>                 rsp.setHeader('Content-Type','text/plain')
>                 return "This is a textfile"
>
> The type of data you return, the default filename the user gets presentend in
> his download dialog ('download.txt' in the example) and the data itself
> is 100% under your control. There should be no problem creating some kind of
> archive inside the view and return in to the user.
>
> Remember: You must always return a plain "str"ing from __call__ if you want
> to manually set the 'Content-Type' -header.

Thanks, it works!

Best regards
Godfryd


More information about the Zope3-users mailing list