Last active
August 29, 2015 14:12
-
-
Save oldj/91d3b4e40229e2268437 to your computer and use it in GitHub Desktop.
在Django中提供大内容(或大文件)下载
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bigFileView(request): | |
u"""在Django中提供大内容(或大文件)下载 | |
@see http://oldj.net/article/django-big-file-response/ | |
""" | |
# do something... | |
def readFile(fn, buf_size=262144): | |
f = open(fn, "rb") | |
while True: | |
c = f.read(buf_size) | |
if c: | |
yield c | |
else: | |
break | |
f.close() | |
file_name = "big_file.txt" | |
response = HttpResponse(readFile(file_name)) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment