在我的情况下,我有Django 1.11服务器充当代理。当您从浏览器中点击“下载”时,它会向django代理发送请求,从其他服务器下载文件并对其进行处理,然后将其发送到浏览器以允许用户下载。我的代理通过块下载并处理文件块。 如何在浏览器准备就绪时向浏览器发送块,以便用户最终下载单个文件?Django 1.11通过块下载文件块
在实践中,我必须让你下载一个尚未准备好的文件,比如流。
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 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
谢谢你,问候。
我终于找到了答案在这里:https://stackoverflow.com/questions/38514919/django-stream-request-from-external-site-as-received 这个问题实际上是一个dupplicate –
是的,这里https://stackoverflow.com/questions/48949022/django-filewrapper-memory-error-serving-big-files-how-to-stream/48949959#48949959 – trinchet
而在这里:https:// stackoverflow。 com/questions/8600843/serving-large-files-with-high-loads-in-django?answertab = votes#tab-top –