Serving large files ( with high loads ) in Django

前端 未结 5 1316
耶瑟儿~
耶瑟儿~ 2020-12-04 13:00

I\'ve been using a method for serving downloads but since it was not secure i decided to change that . ( the method was a link to the original file in storage , but the risk

5条回答
  •  眼角桃花
    2020-12-04 13:18

    Unless you are going to be serving very very small number of such requests, any solution that requires serving your content via django won't be scalable. For anything to scale in future, you'll probably want to move your content storage and serving to to a separate server and then this won't work.

    The recommended way would be to keep static content served through a lighter server (such as nginx). To add security, pass the static server a token from django by setting the cookie or via the get parameters.

    The token should have following values: timestamp, filename, userid. It should be signed via some key by the django app.

    Next, write a small nginx module which checks the token and that the user has indeed access to the file. It should also check that token isn't old enough by checking the timestamp.

提交回复
热议问题