就我而言,我让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
Run Code Online (Sandbox Code Playgroud)
预先谢谢您的问候。