我想上传'F:comic\picture\jepp‘中的zip文件。我使用以下代码:
def sendjepp(request):
docuPath ='F:comic\picture\jepp'
temp = tempfile.TemporaryFile()
f = zipfile.ZipFile(temp, 'w', zipfile.ZIP_DEFLATED)
for dirpath,dirnames,filenames in os.walk(docuPath):
for filename in filenames:
f.write(os.path.join(dirpath,filename))
# f.close()
wrapper = FileWrapper(temp)
response = HttpResponse(wrapper, content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=test.zip'
response['Content-Length'] = temp.tell()
temp.seek(0)
return response我得到了这个错误:

发布于 2021-10-25 15:21:46
当我遇到这个问题时回答,这是我发现的唯一问题。
您需要使用StreamingHttpResponse (docs here)而不是HttpResponse。
https://stackoverflow.com/questions/42361264
复制相似问题