jedie / PyInventory

Web based management to catalog things including state and location etc. using Python/Django.
GNU General Public License v3.0
18 stars 0 forks source link

Use sendfile to serve users own MEDIA files... #29

Open jedie opened 3 years ago

jedie commented 3 years ago

Currently the Django apps serves users MEDIA files by Django's FileResponse...

A better way is that the server used sendfile. A solution is https://pypi.org/project/django-sendfile2/ with a proper server. But Caddy doesn't support this, yet: https://github.com/caddyserver/caddy/issues/3828

jedie commented 3 years ago

In combination with gunicorn we can use OS "sendfile" direct, e.g.:

            file_wrapper = environ.get("wsgi.file_wrapper", FileWrapper)
            return file_wrapper(response.file)

see: https://github.com/evansd/whitenoise/blob/f67cdf3a1afcaa3ee9f636f247ccfee256c9c7be/whitenoise/base.py#L89-L98 https://docs.python.org/3/library/wsgiref.html#wsgiref.util.FileWrapper