Some of the information here may be outdated, please check the book instead
[edit]

Since version 1.22, streaming is the default method used by web2py to serve files from the following directories:

    [web2py working folder]/application/[your app]/static/ 

    [web2py working folder]/application/[your app]/uploads/

For customised file serving function that overrides the default download behavior, web2py will automatically detect whether the returning object is a streaming object (an iterator), or a string object, and serve accordingly.

Examples:

    # streams big file using default byte size for chunks 
    def my_big_file_downloader():        
        ...
        ...
        import os
        filename=request.args[0]
        pathfilename=os.path.join(request.folder,'uploads/', filename)
        return response.stream(open(pathfilename,'rb'), chunk_size=10**6)

    # the old way
    def my_small_file_downloader():
        ...
        import os
        import gluon.contenttype
        filename=request.args[0]
        response.headers['Content-Type']=gluon.contenttype.contenttype(filename)
        pathfilename=os.path.join(request.folder,'uploads/', filename)
        return open('pathfilename', 'rb').read()

You call them with:

    http://[host]/[app]/[controller]/my_big_file_downloader/[filename in uploads]

or

    http://[host]/[app]/[controller]/my_big_file_downloader/[filename in uploads]/[...]

where [...] is the filename you want the downloading user to see.

See also: Infinite data stream http://mdp.cti.depaul.edu/AlterEgo/default/show/32

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.