在我的情況下,我有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 –