【发布时间】:2017-09-21 07:59:12
【问题描述】:
就我而言,我将 Django 1.11 服务器用作代理。当您从浏览器单击“下载”时,它会向 django 代理发送请求,该代理从另一台服务器下载文件并处理它们,之后它们必须将它们“发送”到浏览器以允许用户下载它们。我的代理逐块下载和处理文件。 如何在它们准备好时将块发送到浏览器,以便用户最终下载单个文件?
实际上,我必须让你下载一个尚未准备好的文件,比如流。
def my_download(self, res)
# some code
file_handle = open(local_path, 'wb', self.chunk_size)
for chunk in res.iter_content(self.chunk_size):
i = i+1
print("index: ", i, "/", chunks)
if i > chunks-1:
is_last = True
# some code on the chunk
# Here, instead of saving the chunk locally, I would like to allow it to download it directly.
file_handle.write(chunk)
file_handle.close()
return True
提前谢谢你,问候。
【问题讨论】:
-
我终于在这里找到了答案:stackoverflow.com/questions/38514919/…这个问题其实是重复的
标签: python django download streaming