Hi Guys,

Thanks a lot for the informative posts. My delimma was on DOWNLOAD, and
the suggestion by Robert to mimic serveFile was very helpful.

Now my code resembles:

    @expose()
    def download(self, filename):

        attachment = Attachment.get_by(...)  # get from database
        if attachment is None:
            flash("Attachment not found")
            raise redirect('/')

        headers = cherrypy.response.headers

        # Guess mimetype from extension
        ext = ""
        i = filename.rfind('.')
        if i != -1:
            ext = filename[i:].lower()
        headers['Content-Type'] = mimetypes.types_map.get(ext,
"unknown/unknown")

        headers['Content-Disposition'] = "attachment; filename=%s" %
(filename)

        return attachment.content

While this code works on firefox, requesting feedback on whether there
is any better/more robust solution.

I also have a suggestion: serveFile takes care that the entire file is
not loaded in RAM. But this function does not. While it's possible to
mimic that, will it be a good suggestion to have a brother of serveFile
in cherrypy/turbogears library, which can read directly from database
field? (being compatible with SQLAlchemy PickleType)

thanks
sanjay


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to