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

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.


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

    # the old way
    def my_small_file_downloader():
        import os
        import gluon.contenttype
        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]


    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

© 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.