There is an easier solution:

http://www.cherrypy.org/wiki/FileDownload

Look at the Download class :)

- Sylvain

Selon Lee McFadden <[EMAIL PROTECTED]>:

>
> Here's the code for my download method which streams from the DB:
>
> [code]
>
> @turbogears.expose()
> def download(self, id, **kw):
>     article = NewsPost.get(id)
>
>     if article.mimetype:
>         cherrypy.response.headerMap["Content-Type"] = article.mimetype
>     else:
>         cherrypy.response.headerMap["Content-Type"] =
> "application/x-download"
>
>     cherrypy.response.headerMap["Content-Disposition"] =
> "attachment;filename=%s" % article.filename.replace(" ", "_")
>     cherrypy.response.headerMap["Content-Length"] = "%d" %
> len(article.attachment)
>     return cherrypy.lib.cptools.fileGenerator(StringIO(article.attachment))
>
> [/code]
>
> Hope this helps
>
> Lee
>
> On 12/8/05, Wavy Davy <[EMAIL PROTECTED]> wrote:
> >
> > On 08/12/05, Sylvain Hellegouarch <[EMAIL PROTECTED]> wrote:
> > > Until CP 2.1, CP defauts its content type to text/html, you will be able
> to
> > > change that globally from the config file though a line like:
> > >
> > > server.defaultContentType = 'application/xml'
> >
> > Excellent, ready to switch from HTML to XHTML and the flick of a
> > config option :) Combined with kids outputformat, you can write in
> > validated xhtml and serve it as whatever the hell your customer wants
> > :)
> >
> > > There will be also a new decorator called headers to set HTTP headers per
> page
> > > handler (exposed callable) like this:
> > >
> > > @cherrypy.expose
> > > @cputil.headers([('Content-Type', 'application/atom+xml'),
> ('Content-Language',
> > > 'fr')])
> > > def atom(self):
> > >     return atom doc
> >
> > Good. But is there a reason behind the cputil packaging? Or is this
> > just an example of how it could go? I would prefer cherrypy.headers(),
> > for consistency. Everything to do with controlling cherrypy is behind
> > the cherrypy namespace.
> >
> > --
> > wavy davy
> >
> > "True religion confronts earth with heaven
> > and brings eternity to bear on time"
> >   - A. W. Tozer
> >
>




----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Reply via email to