Django檔案下載,解決Django中文名問題
阿新 • • 發佈:2019-01-22
支援大檔案下載和Django檔案中文名字
#iterator
def readFile(file_name):
f= open(file_name,'rb')
while True:
c= f.read(1024)
if c:
yield c
else:
break;
#down file
def down_File(request):
try:
file_name ='cfdjfdf008好好tf.mp4'
response = StreamingHttpResponse(readFile('D:/'+file_name))
response['mimetype']='application/octet-stream'
response['Content-Type']='text/plain'
# response['Content-Disposition']='attachment; filename*={}'.format(escape_uri_path(file_name))
response['Content-Disposition'] = "attachment; filename*=utf-8''{}".format(escape_uri_path(file_name))
return response;
except:
return HttpResponse("failed!please try it again!")