Allowed force download a file

This commit is contained in:
pcdinh
2016-10-25 16:38:07 +07:00
parent 0deecd6a4e
commit 9d00d0c6c6
2 changed files with 23 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ See request.py for more information
```python
from sanic import Sanic
from sanic.response import json, text
from sanic.response import json, text, file
@app.route("/json")
def post_json(request):
@@ -46,4 +46,11 @@ def query_string(request):
@app.route("/users", methods=["POST",])
def create_user(request):
return text("You are trying to create a user with the following POST: %s" % request.body)
@app.route("/file/<file_id>", methods=["GET",])
def download_a_file(request, file_id):
def find_path_by_id(file_id):
return "/path/to/file.ext"
return file(find_path_by_id(file_id), force_download=True)
```