Comments (12)
@Natim I'm currently looking into this and will submit a PR if/when I figure it out. Do you have any recommendations for this issue?
from django-downloadview.
Specifically, the type of View
I am trying to accelerate is:
django-downloadview/demo/demoproject/object/views.py
Lines 5 to 6 in 563b2a4
django-downloadview/demo/demoproject/object/urls.py
Lines 6 to 11 in 563b2a4
from django-downloadview.
As a note, ObjectDownloadView
is listed as supported for acceleration in the docs: https://django-downloadview.readthedocs.io/en/latest/optimizations/index.html#supported-features-grid
from django-downloadview.
@johnthagen Did you manage to get it working?
from django-downloadview.
@amarandon I did not. The challenge I had was that by using object primary keys, I couldn't find a corollary to how to translate those into something to pass NGINX.
I think this would be a very important addition to this library, but after trying for some time I could not figure it out. I do hope that someone is able to and can share their findings with the community.
from django-downloadview.
@Natim Do you have any insights or directions someone could take who is trying to discover how to do this? Is this something that is intended to be supported?
from django-downloadview.
I guess what you are looking for is probably https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
- https://github.com/jazzband/django-downloadview/blob/45e1219275f9549b60fd8265737171ac450f2161/demo/demoproject/object/views.py
- https://github.com/jazzband/django-downloadview/blob/45e1219275f9549b60fd8265737171ac450f2161/demo/demoproject/nginx/views.py
Basically your ObjectView will return an URL that will be transmitted in a X-Accel header to Nginx which will handle the file.
from django-downloadview.
@Natim So if I understand correctly ObjectDownloadView should add the correct header out of the box and we only need to configure nginx to make use of it? I just had a look in browser's devtools and that doesn't seem to be the case 🤔
from django-downloadview.
If I understand the code correctly it would work like that if you configure the XAccelMiddleware to monitor the path that your ObjectResponse will use.
from django-downloadview.
@Natim What confuses me is what to put in DOWNLOADVIEW_RULES
and how it relates to Django URLs configuration and Nginx configuration.
I have a Photo
model like this:
class Photo(models.Model):
file = models.ImageField(upload_to='uploads/%Y/%m/%d/')
And an ObjectDownloadView
configured in urls.py
like this:
path('photos/<int:pk>', ObjectDownloadView.as_view(model=Photo), name='photo_file'),
This works as expected: files are served through the Python view.
Now in settings.py
I've added django_downloadview.SmartDownloadMiddleware
at the end of my MIDDLEWARE
lists. I've enabled the nginx backend with DOWNLOADVIEW_BACKEND = "django_downloadview.nginx.XAccelRedirectMiddleware"
but now I'm confused as to how I should configure DOWNLOADVIEW_RULES
. I tried this:
DOWNLOADVIEW_RULES = [
{
'source_url': '/photos/',
'destination_url': '/uploads/',
},
]
Along with this entry in nginx config:
location /uploads/ {
internal;
# /home/myuser/myproject contains a directory named 'uploads' which contains uploaded photos
alias /home/myuser/myproject;
}
But this doesn't seem to change anything. In fact I'm not even sure of how to verify that it works. I was kind of expecting a line in nginx log files saying it did the internal redirection but I'm not sure if this expectation is reasonable.
from django-downloadview.
I think the issue is with
DOWNLOADVIEW_RULES = [
{
'source_url': '/photos/',
'destination_url': '/uploads/',
},
]
can you try:
DOWNLOADVIEW_RULES = ['/uploads']
from django-downloadview.
Disclaimer: I had a very quick look at this thread and I've not been coding with Django for some time now...
I haven't figured out where is the issue at the moment.
I'm not even sure of how to verify that it works
As far as I remember, in order to debug, you can:
- disable X-Accel backend in Django settings and check that files are served. You did that already if I understood well.
- enable X-Accel backend in Django settings but comment /uploads/ section in Nginx configuration, then check HTTP response.
- If response does have X-Accel-Redirect header, then it looks like Nginx didn't catch this header (or the value of the header), so check Nginx configuration.
- If response doesn't have X-Accel-Redirect header, then it looks like the middleware didn't catch the URL as expected. So check Django configuration.
There is also some assert_x_accel_redirect() utility to create tests. It may be useful to check that middleware catches the response and transforms it to X-Accel as expected. See https://django-downloadview.readthedocs.io/en/latest/optimizations/nginx.html#test-responses-with-assert-x-accel-redirect
from django-downloadview.
Related Issues (20)
- Dead package
- Drop support for Python 2.7 and Django 1.11
- Proposal to move django-downloadview to JazzBand. HOT 3
- Did this module ever close a file? HOT 4
- mI got the following error while running the demo with "make runserver":django.db.utils.OperationalError: Problem installing fixture '/home/ruihai.jing/TTProgram/django-downloadview-master/demo/demoproject/fixtures/demo.json': Could not load object.Document(pk=1): no such table: object_document HOT 1
- Implement Jazzband guidelines for django-downloadview HOT 5
- Documentation references end of life Python 2.7
- Remove setuptools install_requires entry
- Demo project has settings for end of life Django versions HOT 1
- DjangoRestFramework Integration HOT 4
- Migrating from django-sendfile HOT 2
- Support Django 4.0 HOT 2
- Please make a new pypi release to support Django 4 HOT 1
- Add Async Support HOT 3
- Use Django's built-in FileResponse to address security issue HOT 1
- Very slow download speed from `ObjectDownloadView` HOT 3
- Signal/event once file has been downloaded? HOT 2
- How to use django-downloadview for ensuring only authenticated users can access media files? HOT 2
- Preserve headers of original response
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-downloadview.