Added brief documentation with an example for file_stream

Added test to ensure `file_stream()` works in the test suite.
This commit is contained in:
ashleysommer 2017-05-18 18:12:26 +10:00
parent e155fe403d
commit 181977ad4e
2 changed files with 14 additions and 0 deletions

View File

@ -60,6 +60,16 @@ async def index(request):
return response.stream(streaming_fn, content_type='text/plain')
```
## File Streaming
For large files, a combination of File and Streaming above
```python
from sanic import response
@app.route('/big_file.png')
async def handle_request(request):
return await response.file_stream('/srv/www/whatever.png')
```
## Redirect
```python

View File

@ -37,6 +37,10 @@ async def test_await(request):
async def test_file(request):
return await response.file(os.path.abspath("setup.py"))
@app.route("/file_stream")
async def test_file_stream(request):
return await response.file_stream(os.path.abspath("setup.py"),
chunk_size=1024)
# ----------------------------------------------- #
# Exceptions