python Django 文件下载示例
1 from django.http import StreamingHttpResponse#文件流 2 3 4 def big_file_download(request): 5 # do something... 6 7 def file_iterator(file_name, chunk_size=512): 8 with open(file_name,'rb') as f: 9 while True: 10 c = f.read(chunk_size) 11 if c: 12 yield c 13 else: 14 break 15 16 the_file_name = "big_file.pdf" 17 response = StreamingHttpResponse(file_iterator(the_file_name)) 18 response['Content-Type'] = 'application/octet-stream' 19 response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name) 20 21 return response 22 23 链接:http://www.jianshu.com/p/2ce715671340 25 來源:简书 作者:Gevin
您的资助是我最大的动力!
金额随意,欢迎来赏!
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的
因为,我的写作热情也离不开您的肯定支持,感谢您的阅读,我是【莫柔落切】!
联系或打赏博主【莫柔落切】!https://home.cnblogs.com/u/uge3/