3
요청 응답에서 생성 된 클라이언트에 zip 파일을 보내는 방법을 찾고 있습니다. 이 예에서는 변환 된 JSON 문자열의 zip 파일을 반환하는 url에 JSON 문자열을 보냅니다.Flask : 동적으로 생성되는 zipfile을 클라이언트에 보내는 방법
@app.route('/sendZip', methods=['POST'])
def sendZip():
content = '{"type": "Point", "coordinates": [-105.01621, 39.57422]}'
data = {'json' : content}
r = requests.post('http://ogre.adc4gis.com/convertJson', data = data)
if r.status_code == 200:
zipDoc = zipfile.ZipFile(io.BytesIO(r.content))
return Response(zipDoc,
mimetype='application/zip',
headers={'Content-Disposition':'attachment;filename=zones.zip'})
하지만 내 zip 파일은 비어 있고 플라스크에 의해 반환되는 오류가
Debugging middleware caught exception in streamed response at a point where response
headers were already sent
** ** https://stackoverflow.com/questions/27337013/how-to-send-zip-files-in-the-python-flask-framework – dreftymac