Serve static files with X-Send File

Information freshness

Background and mod_auth_tkt issues

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/

bonus

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.

Finally

We welcome your comments.

Recommended Posts

Serve static files with X-Send File
Upload files with Django
File upload with django
[Day 6] Handle static files
Draw netCDF file with python
Fast file transfer with fabric
Sorting image files with Python (2)
Sort huge files with python
Sorting image files with Python (3)
Sorting image files with Python
Bidirectional file transfer with Pythonista 3
Transfer files with teraterm [Note]
Integrate PDF files with Python
Reading .txt files with Python
About handling Django static files
File upload with Flask + jQuery
Handle JSON files with Matlab
Download csv file with python
Create xlsx file with XlsxWriter