python - Can I add permissions to media django media files? -


i want build app , let user see videos if have permissions or paid video. using django , want add ngnix , gunicorn serve media files. not sure if once user has url of video, how can block him not see video if payment expired or doesn't have permissions. let django serve videos , overwrite server method , if doesn't have access video return 404.

you need implement so-called 'x-sendfile feature'. let's paid-for files served location /protected/ - need add nginx's config:

location /protected/ {     internal;     root   /some/path; } 

then when want serve user file named mycoolflix.mp4 app needs add header x-accel-redirect: /protected/mycoolflix.mp4 , file /some/path/protected/mycoolflix.mp4 served user. more information in nginx documentation here , here. serving files views not idea - makes 1 of django processes busy until download complete, preventing serving other requests.


Comments