1
나는 체리 Py를 통해 사용자에게 제공하기 위해 즉석에서 zip 파일을 생성하고 싶습니다 : 나는 잘못된 zip 파일을 생성 한 다음 코드 시도 :Cherry Py로 파이썬에서 zip 파일 스트림 만들기?
@cherrypy.expose
def ZipDir(self, *args):
path = "\\".join(args)
output = StringIO.StringIO()
file = zipfile.ZipFile(output, "w")
zip_filename = path + ".zip"
cherrypy.response.headers['Content-Type'] = 'application/zip'
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename="%s"' % (zip_filename,)
dir = filter(lambda x: x.lower().endswith(".mp3") or not ("." in x), os.listdir("G:\\Music\\" + path))
for f in dir:
file.write("G:\\Music\\" + path + "\\" + f,f,zipfile.ZIP_DEFLATED)
return output.getvalue()
파일 크기를 잘 대해 보이는, 그러나 그것은 나던 모든 응용 프로그램과 함께 zip 파일로 등록하십시오.