Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jedie opened this issue Nov 23, 2020 · 1 comment
Open

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

jedie opened this issue Nov 23, 2020 · 1 comment

Comments

@jedie
Copy link
Owner

jedie commented Nov 23, 2020

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: caddyserver/caddy#3828

@jedie
Copy link
Owner Author

jedie commented Dec 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant