Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 52 lines (43 sloc) 1.477 kb
8e21f69 @dublo7 Added simple yield server demonstrating streaming content to multiple…
dublo7 authored
1 ---
2 layout: default
3 title: How to Stream Large Files
4 ---
5
6 # How to Stream Large Files
7
8 This is an example of how you can use web.py to stream large files. You'll find it DOES work as advertised, but there are some protocol changes you may have to make to stream files of certain types to certain clients.
9
10 You need the content type and chunked header to make things show up correctly on a typical web browser.
11
12 Simple Example
13 import web
14 import time
15
16 urls = (
17 "/", "count_holder",
18 "/(.*)", "count_down",
19 )
20 app = web.application(urls, globals())
21
22
23 class count_down:
24 def GET(self,count):
25 web.header('Content-type','text/html')
26 web.header('Transfer-Encoding','chunked')
27 yield '<h2>Prepare for Launch!</h2>'
28 j = '<li>Liftoff in %s...</li>'
29 yield '<ul>'
30 count = int(count)
31 for i in range(count,0,-1):
32 out = j % i
33 time.sleep(1)
34 yield out
35 yield '</ul>'
36 time.sleep(1)
37 yield '<h1>Lift off</h1>'
38
39 class count_holder:
40 def GET(self):
41 web.header('Content-type','text/html')
42 web.header('Transfer-Encoding','chunked')
43 boxes = 4
44 delay = 3
45 countdown = 10
46 for i in range(boxes):
47 output = '<iframe src="/%d" width="200" height="500"></iframe>' % (countdown - i)
48 yield output
49 time.sleep(delay)
50
51 if __name__ == "__main__":
52 app.run()
Something went wrong with that request. Please try again.