mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-03 03:41:34 +00:00
parent
60a145afbb
commit
b3d83b1b0b
@ -286,22 +286,26 @@ class ProjectHandler:
|
||||
controller = Controller.instance()
|
||||
project = yield from controller.get_loaded_project(request.match_info["project_id"])
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
|
||||
# We need to do that now because export could failed and raise an HTTP error
|
||||
# that why response start need to be the later possible
|
||||
response.content_type = 'application/gns3project'
|
||||
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
|
||||
response.enable_chunked_encoding()
|
||||
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
|
||||
response.content_length = None
|
||||
response.start(request)
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
|
||||
# We need to do that now because export could failed and raise an HTTP error
|
||||
# that why response start need to be the later possible
|
||||
response.content_type = 'application/gns3project'
|
||||
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
|
||||
response.enable_chunked_encoding()
|
||||
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
|
||||
response.content_length = None
|
||||
response.start(request)
|
||||
|
||||
for data in datas:
|
||||
response.write(data)
|
||||
yield from response.drain()
|
||||
for data in datas:
|
||||
response.write(data)
|
||||
yield from response.drain()
|
||||
|
||||
yield from response.write_eof()
|
||||
yield from response.write_eof()
|
||||
# Will be raise if you have no space left or permission issue on your temporary directory
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPNotFound(text="Can't export project: {}".format(str(e)))
|
||||
|
||||
@Route.post(
|
||||
r"/projects/{project_id}/import",
|
||||
|
Loading…
Reference in New Issue
Block a user