On Tue, 2002-02-05 at 20:29, Matt Feifarek wrote:
> | Well, you should do a loop on reading and flush it.
> |
> | I believe this gives a good example:
> | http://webware.colorstudy.net/twiki/bin/view/Webware/FileStreaming
> AndContentDisposition
> 
> colorstudy.net seems to have fallen off of DNS. Actually, now that I think
> of it, it has been all day. Can you quickly explain what you mean by
> loop/flush? Thanks.

Arr.... Does anyone know of a place that does reliable, affordable DNS?

Anyway, you want to do something like:

    self.response().setHeader('Content-type', 'application/whatever')

    f = open(filename)
    self.response().flush() # This turns on streaming
    while 1:
        value = f.read(4096)
        if not value: break
        self.response().write(value)

This way the file is streamed to the user immediately, and less memory
is used.

> | There's other tricks with local (or even remote) redirects that you can
> | do -- they'd perform better, and should be fine unless you want to
> | secure files.
> 
> Any references for those tricks?

Well, you can just do a redirect (assuming there's a portion of your
site that is served as normal from the filesystem).  I think if you set
the Status header correctly when you do a redirect, Apache will serve
the file you referred it to, but won't redirect the users browser.  I'm
vague on it myself.

> If you're referring to my example, yeah, it's stupid (why send a gif or any
> other static file through a servlet) but what if you're building a pdf from
> a webkit servlet or some other dynamic thing.
> 
> Another good example would seem to be stylesheets that modify themselves to
> browser-type or based on session or state or whatever.

All those tricks don't really apply to anything dynamic, even if it is
non-HTML.  In those cases, you mostly use normal python and just write
out the results.  I believe someone wrote something on dynamic PDF for
the Wiki though.

  Ian



_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to