This is a continuation. http://qiita.com/amedama/items/3f2197cadc1ea7d6374e
X-SendFile
And it's X-Send File.
If this is included in the Response header, the web server under the WSGI app, that is Apache this time, will Before returning a response to the user, it expands the path and starts sending the file to the user. There are more articles around nginx, but if you put a module in another, it will work with Apache.
Evaluation of performance is ... Of course through.
Probably not if the DB contains files.
http://stackoverflow.com/questions/7296642/django-understanding-x-sendfile
For Debian / Ubuntu Apache2, include libapache2-mod-xsendfile.
# prepare "@project_member_required" by yourself
@login_required
@project_member_required
def download_project_file(request, project_name, file_name):
response = HttpResponse()
# prepare this function by yourself
download_path = construct_path_from_file_name(file_name))
response['X-Sendfile'] = download_path
response['Content-Type'] = ''
return response
In the above case
On Apache settings
XSendFile on
XSendFilePath /opt/yourproject/downloads
If you do, / opt / yourproject / downloads will be whitelisted. Conversely, if you specify the wrong path, nothing will be sent.
Reference: https://tn123.org/mod_xsendfile/
django-sendfile (https://github.com/johnsensible/django-sendfile)
The first thing that appears in the google result of "django X-SendFile" is a land mine. This is an implementation that reads a file on django, expands it, and returns it as content, which is far from efficient.
We welcome your comments.
Recommended Posts