I want to build an app and let user to see some videos just if they have permissions or they paid for that video. I am using Django and I want to add ngnix and gunicorn to serve media files. I am not sure if once the user has the url of the video, how can I block him to not see the video if his payment expired or he doesn't have the permissions. For now I let django to serve the videos and I overwrite the server method and if he doesn't have access to video I return 404.
score:7
You need to implement the so-called 'X-Sendfile feature'. Let's say your paid-for files will be served from location /protected/
- you need to add to nginx's config:
location /protected/ {
internal;
root /some/path;
}
then when you want to serve your user a file named mycoolflix.mp4
your app needs to add header X-Accel-Redirect: /protected/mycoolflix.mp4
and the file /some/path/protected/mycoolflix.mp4
will be served to the user. More information in the nginx documentation here and here.
Serving files from your views is not a good idea - it makes one of your Django processes busy until the download is complete, preventing it from serving other requests.
Credit To: stackoverflow.com
Related Query
- Can I add permissions to media django media files?
- Can not able to serve media files on cpanel django
- How can i get django to process media files on production?
- Django can not access Image and Media files
- How can I use Django permissions without defining a content type or model?
- How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?
- Page not found 404 Django media files
- Django delete unused media files
- Django media URLs in CSS files
- How can my django model DateField add 30 days to the provided value?
- How to serve django media files via nginx ?
- How do you Require Login for Media Files in Django
- Can i add help text in django model fields
- How can I add a button into django admin change list view page
- For a django model, how can I get the django admin URL to add another, or list objects, etc.?
- Should I add Django admin static files to my git repo?
- Can you add parameters to Django custom admin actions?
- How can I use relative path to read local files in Django app?
- Serving Media files during deployment in django 1.8
- How to serve media files on Django production environment?
- How do I serve media files in a local Django environment?
- In Django admin, how can I hide Save and Continue and Save and Add Another buttons on a model admin?
- Confusion in Django admin, static and media files
- How to add django rest framework permissions on specific method only ?
- How can I add a test method to a group of Django TestCase-derived classes?
- Using Heroku for Django Media Files
- Django media files not showing with Debug = False on production - Django 1.10
- How to install gnu gettext (>0.15) on windows? So I can produce .po/.mo files in Django
- Django serving media files (user uploaded files ) in openshift
- how to add Permissions in Django to Models and Test it using the shell
More Query from same tag
- Expiring session on browser close
- Decimal to JSON
- WSGIRequest' object has no attribute 'session_key
- Overiding save for just one field in Django
- I've got error message : TypeError: unsupported operand type(s) for %: 'DeferredAttribute' and 'dict' in django
- How do I get value from another filter in a django filter set
- Django: class 'Project' does not define '_add_', so the '+' operator cannot be used on its instances
- how to run Django application in apache2
- Dynamic queryset into form
- MySQL LIKE Query changes in 5.1 to 5.6 to full table scan
- Clarification needed for `Including extra context` to a serializer in Django REST Framework
- Can I use digital ocean spaces for user uploaded files with django?
- django-filter dropdown menu
- How to lock a critical section in Django?
- In Django, can the choices defined in a model class be accessed elsewhere outside the model class?