各位朋友们好,我用django写了一个网页,可以下载zip的压缩包文件,但是如果该zip文件名含有中文,比如如果zip文件名是”math.zip”,那么下载的时候显示的文件名也是”math.zip”,但是如果我提供的下载文件名是”1.1数的分类”,就会出现如” 79d6c6d5”这种乱码文件
下面是我的django处理下载zip压缩包的代码:
def zip_download(request):
try:
temp = open(zipfileName , "rb")
except IOError as ex:
return HttpResponse("Open zip error")
wrapper = FileWrapper(temp)
response = HttpResponse(wrapper, content_type='application/zip')
realZipfileName = os.path.split(zipfileName)[1]
response['Content-Encoding'] = 'utf-8'
response['Content-Disposition'] = 'attachment; filename=%s' % realZipfileName
response['Content-Length'] = temp.tell()
temp.seek(0)
return response
请诸位大神指点一下,如何才能避免下载带有中文的zip压缩包乱码的问题,在此先谢过各位朋友。