Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving a downloadable file (huge) from remote with django

I am trying to have my server serving a huge file from another server. However, to protect my credential against that remote server, I can't simply redirect the requester to the file url; on the other hand, although using StreamingHttpResponse doesn't add content to memory or hardrive, it does takes more time - the server still need to download the file from the remote then serve it, which doubles up the response time. Is there any way I can "redirect" content of the remote file, without actually downloading it? Thanks.

like image 581
Yishen Chen Avatar asked Oct 26 '25 20:10

Yishen Chen


1 Answers

you can read the file and stream it at the same time.

look at the code in Django 1.5 - using the new StreamingHttpResponse - all you need to do is put the code that reads from the other server into the generator. each time you read some data from the socket, write it to the streaming output.

like image 126
andrew cooke Avatar answered Oct 28 '25 10:10

andrew cooke