从django提供远程的可下载文件(巨大) [英] Serving a downloadable file (huge) from remote with django

查看:160
本文介绍了从django提供远程的可下载文件(巨大)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的服务器从另一个服务器提供一个巨大的文件。但是,为了保护我的凭据免受该远程服务器的影响,我不能简单地将请求者重定向到文件url;另一方面,虽然使用 StreamingHttpResponse 不会将内容添加到内存或硬盘,但它需要更多的时间 - 服务器仍然需要从远程服务器下载文件,然后服务它使响应时间加倍。有什么办法可以重定向远程文件的内容,而不实际下载?谢谢。

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.

推荐答案

您可以同时阅读文件并发送。

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

查看 Django 1.5中的代码 - 使用新的StreamingHttpResponse - 所有你需要做的是将从其他服务器读取的代码放入生成器。每次从套接字读取一些数据时,将其写入流输出。

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.

这篇关于从django提供远程的可下载文件(巨大)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆